def test_cluster_read(self): luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) cluster = luna.Cluster(mongo_db=self.db) doc = self.db['cluster'].find_one({'_id': cluster._id}) for attr in expected: self.assertEqual(doc[attr], expected[attr])
def setUp(self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ {'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64'}, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster( mongo_db=self.db, create=True, path=self.path, user=getpass.getuser(), ) self.osimage = luna.OsImage( name='testosimage', path=self.path, mongo_db=self.db, create=True, )
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.group = luna.Group(name='testgroup', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True) self.new_group1 = luna.Group(name='new1', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True) self.node = luna.Node(group=self.group.name, mongo_db=self.db, create=True) self.network11 = luna.Network(name="net11", mongo_db=self.db, create=True, NETWORK='10.51.0.0', PREFIX=16) self.network61 = luna.Network(name="net61", mongo_db=self.db, create=True, NETWORK='fe80::', PREFIX=64, version=6)
def luna_cluster_absent(data): for k, v in data.items(): exec('%s = v' % k) try: cluster = luna.Cluster() cluster.delete(force=True) return False, True, '' except Exception as e: return True, False, str(e) + traceback.format_exc()
def test_init_cluster_with_defaults(self): cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) doc = self.db['cluster'].find_one({'_id': cluster._id}) expected['path'] = self.path for attr in expected: self.assertEqual(doc[attr], expected[attr])
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages print self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.cluster.set('path', self.path) self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.group = luna.Group( name='testgroup', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True, ) self.group_new = luna.Group( name='testgroup_new', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True, ) self.node = luna.Node( group=self.group.name, mongo_db=self.db, create=True, )
def setUp(self): self.bind = create_datastore('mim:///luna') self.db = self.bind.db.luna self.path = '/tmp/luna' if not os.path.exists(self.path): os.makedirs(self.path) cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser())
def setUpClass(self): print self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser())
def setUp(self): print self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.bmc = luna.BMCSetup(name='testbmc', mongo_db=self.db, create=True)
def status(self): res, comment = True, "" if luna is None: res = False comment = "Luna is not installed" return res, comment logging.getLogger("requests").setLevel(logging.WARNING) port = int(luna.Cluster().get('frontend_port')) addr = luna.Cluster().get('frontend_address') url = 'http://{}:{}/luna?step=boot'.format(addr, port) r = requests.get(url) content = r.content.split('\n') if r.ok and len(content) > 0 and content[0] == '#!ipxe': return res, comment res = False comment = "Answer from '{}' is wrong".format(url) return res, comment
def setUp(self): print self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.network = luna.Network(mongo_db=self.db, create=True, name='cluster', NETWORK='10.141.0.0', PREFIX=16)
def setUp(self): self.bind = create_datastore('mim:///luna') self.db = self.bind.db.luna self.path = '/tmp/luna' if not os.path.exists(self.path): os.makedirs(self.path) cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.net = luna.Network(name='test', mongo_db=self.db, create=True, NETWORK='172.16.1.0', PREFIX='24', ns_hostname='controller', ns_ip='172.16.1.254')
def setUp(self): print self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.net = luna.Network(name='test', mongo_db=self.db, create=True, NETWORK='172.16.1.0', PREFIX='24', ns_hostname='controller', ns_ip='172.16.1.254')
def setUp(self): print self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.net = luna.Network(name='test', mongo_db=self.db, create=True, NETWORK='fdee:172:30:128::', PREFIX=64, ns_hostname='controller', ns_ip='fdee:172:30:128::254:254', version=6)
import luna cl = luna.Cluster() cl._create_dhcp_config()
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.cluster.set('path', self.path) self.cluster.set('frontend_address', '127.0.0.1') self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.net = luna.Network( 'testnet', mongo_db=self.db, create=True, NETWORK='fe80::', PREFIX=64, ) self.net.set('ns_hostname', 'master') self.group = luna.Group( name='testgroup', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True, ) self.group.set_net_to_if('eth0', self.net.name) self.nodes = [] for i in range(10): self.nodes.append( luna.Node( group=self.group, create=True, mongo_db=self.db, )) self.net = luna.Network(name=self.net.name, mongo_db=self.db)
def luna_cluster_present(data): data.pop('state') makedhcp = data.pop('makedhcp') makedns = data.pop('makedns') dhcp_net = data.pop('dhcp_net') dhcp_range_start = data.pop('dhcp_range_start') dhcp_range_end = data.pop('dhcp_range_end') native_dhcp_ha = data.pop('native_dhcp_ha') if data['path'] is not None: data['path'] = os.path.abspath(data['path']) changed = False res = True try: cluster = luna.Cluster() except RuntimeError: if data['frontend_address'] is None: msg = 'frontend_address should be specified on creation' return True, False, msg init = {} for key in data: if key in ['nodeprefix', 'nodedigits', 'path', 'user']: init[key] = data[key] init['create'] = True cluster = luna.Cluster(**init) changed = True try: cluster = luna.Cluster() out = '' for key in data: if data[key] is not None and cluster.get(key) != data[key]: out += '{}={},'.format(key, data[key]) changed = True res &= cluster.set(key, data[key]) if makedns: if not cluster.makedns(): return True, False, 'Unable to build DNS config' changed = True if makedhcp: no_ha = not native_dhcp_ha if dhcp_net: if not (dhcp_range_start and dhcp_range_end): return True, False, ('Unable to build DHCP config. ' + 'Network range should be specified') else: if dhcp_range_start or dhcp_range_end: return True, False, ('Unable to build DHCP config. ' + 'Network should be specified.') need_to_rebuild_dhcp = False old_dhcp_net = cluster.get('dhcp_net') old_dhcp_range_start = cluster.get('dhcp_range_start') old_dhcp_range_end = cluster.get('dhcp_range_end') if (old_dhcp_net != dhcp_net or old_dhcp_range_start != dhcp_range_start or old_dhcp_range_end != dhcp_range_end): need_to_rebuild_dhcp = True if need_to_rebuild_dhcp: if not cluster.makedhcp(dhcp_net, dhcp_range_start, dhcp_range_end, no_ha): return True, False, 'Unable to build DHCP config.' changed = True return not res, changed, str(cluster) + ' ' + out except Exception as e: return True, False, str(e) + traceback.format_exc()
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path #osimage_path = self.sandbox.create_osimage() self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.cluster.set("frontend_address", "127.0.0.1") self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.bmcsetup = luna.BMCSetup(name='bmcsetup', mongo_db=self.db, create=True) self.net1 = luna.Network(name='cluster', NETWORK='10.11.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net2 = luna.Network(name='external', NETWORK='10.12.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net3 = luna.Network(name='ib', NETWORK='10.13.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net6 = luna.Network(name='net6', NETWORK='fe80::', PREFIX=64, mongo_db=self.db, create=True, version=6) self.prescript = 'pre' self.postscript = 'post' self.partscript = 'part' self.nics = {'eth0': 'PARM=1', 'eth1': 'PARM=2', 'ib0': 'PARM=3'} self.group = luna.Group(name='compute', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True)
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() if self.sandbox.dbtype != 'mongo': raise unittest.SkipTest( 'This test can be run only with MongoDB as a backend.') self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.group1 = luna.Group(name='testgroup1', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True) self.group2 = luna.Group(name='testgroup2', osimage=self.osimage.name, mongo_db=self.db, interfaces=['BOOTIF'], create=True) self.net11 = luna.Network(name='net11', NETWORK='10.11.0.0', PREFIX=16, mongo_db=self.db, create=True) self.group1.set_net_to_if('eth0', self.net11.name) self.group2.set_net_to_if('BOOTIF', self.net11.name) self.node1 = luna.Node(group=self.group1.name, mongo_db=self.db, create=True) self.node2 = luna.Node(group=self.group2.name, mongo_db=self.db, create=True) self.node1.set_mac('00:11:22:33:44:55') self.node2.set_mac('01:11:22:33:44:55') self.group1 = luna.Group(name=self.group1.name, mongo_db=self.db) self.group2 = luna.Group(name=self.group2.name, mongo_db=self.db) self.net11 = luna.Network(name=self.net11.name, mongo_db=self.db) self.node1 = luna.Node(name=self.node1.name, mongo_db=self.db) self.node2 = luna.Node(name=self.node2.name, mongo_db=self.db)
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.group = luna.Group(name='testgroup', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True) self.net11 = luna.Network(name='net11', NETWORK='10.11.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net11.set('ns_hostname', 'master') self.net61 = luna.Network(name='net61', NETWORK='fe90::', PREFIX=64, mongo_db=self.db, create=True) self.net61.set('ns_hostname', 'master') self.group.set_net_to_if('eth0', self.net11.name) self.group.set_net_to_if('eth0', self.net61.name) self.group = luna.Group(name=self.group.name, mongo_db=self.db) self.node = luna.Node(group=self.group.name, mongo_db=self.db, create=True) self.switch = luna.Switch(name='sw01', network=self.net11.name, mongo_db=self.db, create=True) self.switch.set('ip', '10.11.1.1') self.otherdev = luna.OtherDev(name='pdu01', network=self.net11.name, ip="10.11.2.1", mongo_db=self.db, create=True) self.net11 = luna.Network(name=self.net11.name, mongo_db=self.db) self.node = luna.Node(name=self.node.name, mongo_db=self.db) self.group = luna.Group(name=self.group.name, mongo_db=self.db)
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.cluster.set("frontend_address", "127.0.0.1") self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.bmcsetup = luna.BMCSetup(name='bmcsetup', mongo_db=self.db, create=True) self.net1 = luna.Network(name='cluster', NETWORK='10.11.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net2 = luna.Network(name='external', NETWORK='10.12.0.0', PREFIX=16, mongo_db=self.db, create=True) self.net3 = luna.Network(name='ib', NETWORK='10.13.0.0', PREFIX=16, mongo_db=self.db, create=True) self.prescript = 'pre' self.postscript = 'post' self.partscript = 'part' self.nics = {'BOOTIF': 'PARM=1', 'eth1': 'PARM=2', 'ib0': 'PARM=3'} self.group = luna.Group(name='compute', osimage=self.osimage.name, mongo_db=self.db, interfaces=['BOOTIF'], create=True) # mocking osimage boot stuff with mock.patch('os.path'), \ mock.patch('shutil.copy'), \ mock.patch('os.remove'), \ mock.patch('os.chown'), \ mock.patch('os.chmod'), \ mock.patch('subprocess.Popen') as mock_subprocess_popen, \ mock.patch('os.open'), \ mock.patch('os.chroot'), \ mock.patch('os.fchdir'), \ mock.patch('os.close'), \ mock.patch('os.chdir'), \ mock.patch('shutil.move'), \ mock.patch('libtorrent.add_files'), \ mock.patch('libtorrent.set_piece_hashes'): (mock_subprocess_popen.return_value.stderr.readline.return_value ) = '' self.osimage.copy_boot() self.osimage.create_tarball() self.osimage.create_torrent() group_json = self.db['group'].find_one({'_id': self.group._id}) osimage_json = self.db['osimage'].find_one({'_id': self.osimage._id}) self.install_expected_dict = { 'torrent_if': '', 'partscript': group_json['partscript'], 'tarball': osimage_json['tarball'] + '.tgz', 'bmcsetup': {}, 'interfaces': { 'BOOTIF': { 'options': '', '4': { 'ip': '', 'netmask': '', 'prefix': '', }, '6': { 'ip': '', 'netmask': '', 'prefix': '', } } }, 'prescript': '', 'domain': '', 'postscript': group_json['postscript'], 'kernopts': '', 'kernver': '3.10-999-el0.x86_64', 'torrent': osimage_json['torrent'] + '.torrent' }
def setUp( self, mock_rpm_addmacro, mock_rpm_transactionset, ): print packages = [ { 'VERSION': '3.10', 'RELEASE': '999-el0', 'ARCH': 'x86_64' }, ] mock_rpm_addmacro.return_value = True mock_rpm_transactionset.return_value.dbMatch.return_value = packages self.sandbox = Sandbox() self.db = self.sandbox.db self.path = self.sandbox.path self.cluster = luna.Cluster(mongo_db=self.db, create=True, path=self.path, user=getpass.getuser()) self.cluster.set('path', self.path) self.cluster.set('frontend_address', '127.0.0.1') self.osimage = luna.OsImage(name='testosimage', path=self.path, mongo_db=self.db, create=True) self.net1 = luna.Network( 'testnet1', mongo_db=self.db, create=True, NETWORK='10.50.0.0', PREFIX=16, ) self.net2 = luna.Network( 'testnet2', mongo_db=self.db, create=True, NETWORK='10.51.0.0', PREFIX=16, ) self.group = luna.Group( name='testgroup', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True, ) self.group_new = luna.Group( name='testgroup_new', osimage=self.osimage.name, mongo_db=self.db, interfaces=['eth0'], create=True, ) self.node = luna.Node( group=self.group.name, mongo_db=self.db, create=True, ) self.boot_expected_dict = { 'domain': '', 'initrd_file': '', 'mac': '', 'kernel_file': '', 'localboot': 0, 'name': 'node001', 'service': 0, 'net': {}, 'hostname': 'node001', 'kern_opts': '', 'bootproto': 'dhcp' } self.install_expected_dict = { 'torrent_if': '', 'setupbmc': True, 'partscript': 'mount -t tmpfs tmpfs /sysroot', 'name': 'node001', 'tarball': '', 'bmcsetup': {}, 'interfaces': { 'BOOTIF': { 'options': '', '4': { 'ip': '', 'netmask': '', 'prefix': '', }, '6': { 'ip': '', 'netmask': '', 'prefix': '', } }, 'eth0': { 'options': '', '4': { 'ip': '', 'netmask': '', 'prefix': '', }, '6': { 'ip': '', 'netmask': '', 'prefix': '', } } }, 'prescript': '', 'domain': '', 'hostname': 'node001', 'postscript': ('cat << EOF >> /sysroot/etc/fstab\n' + 'tmpfs / tmpfs defaults 0 0\n' + 'EOF'), 'kernopts': '', 'kernver': '3.10-999-el0.x86_64', 'torrent': '', 'mac': '', }