def test_change_switch(self): if self.sandbox.dbtype != 'mongo': raise unittest.SkipTest( 'This test can be run only with MongoDB as a backend.') net = luna.Network( 'testnet', mongo_db=self.db, create=True, NETWORK='10.50.0.0', PREFIX=16, ) switch1 = luna.Switch( 'test1', network=net.name, mongo_db=self.db, create=True, ) switch2 = luna.Switch( 'test2', network=net.name, mongo_db=self.db, create=True, ) self.node.set_switch(switch1.name) self.node.set_switch(switch2.name) d1 = self.db['node'].find_one({'name': self.node.name}) d2 = self.db['switch'].find_one({'name': switch1.name}) d3 = self.db['switch'].find_one({'name': switch2.name}) self.assertEqual(d1['switch'], switch2.DBRef) self.assertEqual(len(d2['_usedby_']), 0) self.assertEqual(len(d3['_usedby_']['node']), 1) self.assertEqual(d1['switch'], switch2.DBRef)
def luna_switch_present(data): data.pop('state') name = data.pop('name') changed = False ret = True try: switch = luna.Switch(name=name) except RuntimeError: if data['network'] is None: err_msg = "Network needs to be specified" return True, changed, err_msg if data['ip'] is None: err_msg = "IP address needs to be specified" return True, changed, err_msg args = {} for key in data: if data[key] is not None: args[key] = data[key] args['name'] = name args['create'] = True switch = luna.Switch(**args) changed = True # we need to check keys in particular order # can't change ip before network keys = ['read', 'rw', 'oid', 'comment', 'network', 'ip'] for key in keys: if data[key] is not None and switch.get(key) != data[key]: changed = True ret &= switch.set(key, data[key]) return not ret, changed, str(switch)
def test_create_switch_with_defaults(self): switch = luna.Switch(mongo_db=self.db, create=True, name='switch01', network=self.network.name, ip='10.141.100.1') self.assertTrue(switch)
def luna_switch_absent(data): name = data['name'] try: switch = luna.Switch(name=name) except RuntimeError: return False, False, name return not switch.delete(), True, name
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) self.switch = luna.Switch(mongo_db=self.db, create=True, name='switch01', network=self.network.name, ip='10.141.100.1')
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)