cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
check.py
Go to the documentation of this file.
1 ##
2 #
3 # @author Maciej Nabozny <mn@mnabozny.pl>
4 #
5 
6 import subprocess
7 import libvirt
8 import stat
9 import pwd
10 import os
11 
12 
14  print "Checking cm connection..."
15  try:
16  cm.send_request('/ci/storage/get_list/')
17  except:
18  raise Exception('cm_cannot_connect')
19 
21  print "Checking images pool..."
22  try:
23  print "\t...could be accessed through libvirt"
24  conn = libvirt.open(lv_address)
25  except:
26  raise Exception('libvirt_error')
27 
28  try:
29  print "\t...exists"
30  pool = conn.storagePoolLookupByName('images')
31  except:
32  raise Exception('images_pool_not_found')
33 
34  try:
35  print "\t...has images pool"
36  vol = pool.storageVolLookupByName('info')
37  except:
38  raise Exception('images_pool_has_no_info')
39 
40  try:
41  print "\t...is writable"
42  f = open(vol.path().replace('/info', '/write_test'), 'w')
43  f.close()
44  os.remove(vol.path().replace('/info', '/write_test'))
45  except:
46  raise Exception('images_pool_not_writable')
47  print "\t...ok"
48 
50  print "Checking cc1 user..."
51  try:
52  print "\t...exists"
53  u = pwd.getpwnam('cc1')
54  except:
55  raise Exception('cc1_user_not_exists')
56 
57  print "\t...has 331 uid"
58  if u.pw_uid != 331:
59  raise Exception('cc1_user_is_not_331_uid')
60 
61  print "\t...has 331 gid"
62  if u.pw_gid != 331:
63  raise Exception('cc1_user_is_not_331_gid')
64 
65  print "\t...could connect with him self"
66  if subprocess.call(['ssh', '-o', 'PasswordAuthentication=no', 'cc1@localhost', '/bin/true']) != 0:
67  raise Exception('cc1_ssh_error')
68 
69  print "\t...ok"
70 
72  print "Checking permissions..."
73 
74  if ('%o' % os.stat('/var/lib/cc1/.ssh/id_rsa').st_mode)[-3:] != '600':
75  raise Exception('ssh_key_wrong_permission')
76 
77  if os.stat('/etc/cc1/node/config.py').st_uid != 331:
78  raise Exception('node_config_wrong_owner')
79 
80  print '\t...ok'
81 
82 
84  print "Checking qemu.conf file..."
85 
86  qemu = open('/etc/libvirt/qemu.conf', 'r').readlines()
87  user = False
88  group = False
89  dynamic_ownership = False
90 
91  for line in qemu:
92  if 'user' in line and 'root' in line and not line.startswith('#'):
93  user = True
94  if 'group' in line and 'root' in line and not line.startswith('#'):
95  user = True
96  if 'dynamic_ownership' in line and '0' in line and not line.startswith('#'):
97  user = True
98 
99  if not user and not group and not dynamic_ownership:
100  raise Exception('qemu_not_configured')
101 
102  print "\t...ok"
103 
105  print "Libvirt check is not implemented"
106 
107 
109  print "Checking hooks..."
110  if not os.path.exists('/usr/sbin/cc1_node_hook'):
111  print "\t...script exists"
112  raise Exception('script_not_exists')
113 
114  mode = os.stat('/usr/sbin/cc1_node_hook').st_mode
115  if mode & stat.S_IXUSR and mode & stat.S_IXGRP and mode & stat.S_IXOTH:
116  print "\t...script is executable"
117  else:
118  raise Exception('script_not_executable')
119 
120  if not os.path.exists('/etc/libvirt/hooks/qemu'):
121  print "\t...exists"
122  raise Exception('hook_not_exists')
123 
124  mode = os.stat('/etc/libvirt/hooks/qemu').st_mode
125  if mode & stat.S_IXUSR and mode & stat.S_IXGRP and mode & stat.S_IXOTH:
126  print "\t...is executable"
127  else:
128  raise Exception('hook_not_executable')
129 
130  print "\t...ok"
131 
132 
134  print "Checking storages..."
135  conn = libvirt.open(lv_address)
136 
137  print "\t...retreive storage list from libvirt"
138  lv_storages = []
139  for storage_name in conn.listStoragePools():
140  lv_storages.append(conn.storagePoolLookupByName(storage_name))
141 
142  print "\t...retreive storage list from cm"
143  cm_storages = cm.send_request('/ci/storage/get_list/')['data']
144 
145  for storage in cm_storages:
146  print "\t...if storage %s exists" % storage
147  lv_storage_names = [s.name() for s in lv_storages]
148  if not storage in lv_storage_names:
149  raise Exception('storage_not_mounted')
150 
151  for storage in lv_storages:
152  print "\t...if storage %s is running" % storage.name()
153  if storage.name == 'images':
154  continue
155  elif storage.name() in cm_storages and storage.info()[0] != libvirt.VIR_STORAGE_POOL_RUNNING:
156  raise Exception('storage_not_running')
157 
158  print "\t...ok"
159 
160 
162  print "Checking public ip redirections..."
163  r = subprocess.call('sudo /usr/sbin/cc1_node_public_ip check', shell=True)
164  if r != 0:
165  raise Exception('public_ip_failed')
166  print "\t...ok"
167 
168