def testRenameWithProperties(self): rack1 = BasicRack('rack1') rack1.set_attr(key='maxu', subkey='property', value=48) for x in range(3): rack1.add_attr(key='foo', subkey='bar', value=1, number=None) clusto.rename('rack1', 'rack2') rack2 = clusto.get_by_name('rack2') self.assertEqual(rack2.attrs(key='maxu', subkey='property')[0].value, 48) self.assertEqual(len(rack2.attrs(key='maxu')), 1) self.assertEqual(len(rack2.attrs(key='foo', subkey='bar')), 3)
def testAddingToDoubleDigitLocationThenSingleDigitLocation(self): r1, r2 = [clusto.get_by_name(r) for r in ['r1', 'r2']] s1 = BasicServer('s1') s2 = BasicServer('s2') r1.insert(s1, 11) r1.insert(s2, 1) clusto.flush() s = clusto.get_by_name('s1') self.assertEqual(sorted(BasicRack.get_rack_and_u(s)['RU']), [11]) self.assertEqual(sorted(BasicRack.get_rack_and_u(s2)['RU']), [1])
def testGettingRackAndU(self): r1, r2 = [clusto.get_by_name(r) for r in ['r1', 'r2']] s = BasicServer('s1') clusto.flush() r1.insert(s, 13) clusto.flush() s = clusto.get_by_name('s1') res = BasicRack.get_rack_and_u(s) self.assertEqual(res['rack'].name, 'r1') self.assertEqual(res['RU'], [13]) res2 = BasicRack.get_rack_and_u(BasicServer('s2')) self.assertEqual(res2, None)
def data(self): r1 = BasicRack('r1') sw1 = BasicNetworkSwitch('sw1') s1 = BasicServer('s1') p1 = PowerTowerXM('p1') r1.insert(p1, (10, 11)) r1.insert(sw1, 12) r1.insert(s1, 1)
def testGettingRackAndU(self): r1, r2 = [clusto.get_by_name(r) for r in ['r1','r2']] s=BasicServer('s1') clusto.flush() r1.insert(s, 13) clusto.flush() s = clusto.get_by_name('s1') res = BasicRack.get_rack_and_u(s) self.assertEqual(res['rack'].name, 'r1') self.assertEqual(res['RU'], [13]) res2 = BasicRack.get_rack_and_u(BasicServer('s2')) self.assertEqual(res2, None)
def testAddingToDoubleDigitLocationThenSingleDigitLocation(self): r1, r2 = [clusto.get_by_name(r) for r in ['r1','r2']] s1 = BasicServer('s1') s2 = BasicServer('s2') r1.insert(s1, 11) r1.insert(s2, 1) clusto.flush() s = clusto.get_by_name('s1') self.assertEqual(sorted(BasicRack.get_rack_and_u(s)['RU']), [11]) self.assertEqual(sorted(BasicRack.get_rack_and_u(s2)['RU']), [1])
def testServerRackLocation(self): r = clusto.get_by_name('r1') s = clusto.get_by_name('s1') self.assertEqual(BasicRack.get_rack_and_u(s)['RU'], [1]) self.assertEqual(r.get_device_in(12), clusto.get_by_name('sw1')) self.assertEqual(r.get_device_in(10), clusto.get_by_name('p1')) self.assertEqual(r.get_device_in(11), clusto.get_by_name('p1'))
def data(self): r1 = BasicRack('r1') sw1 = BasicNetworkSwitch('sw1') s1 = BasicServer('s1') p1 = PowerTowerXM('p1') r1.insert(p1, (10,11)) r1.insert(sw1, 12) r1.insert(s1, 1)
def testCanAddADeviceToMultipleAdjacentUs(self): """ you should be able to add a device to multiple adjacent RUs """ r1, r2 = [clusto.get_by_name(r) for r in ['r1', 'r2']] s1 = BasicServer('s1') s2 = BasicServer('s2') r1.insert(s1, [1, 2, 3]) clusto.flush() s = clusto.get_by_name('s1') self.assertEqual(sorted(BasicRack.get_rack_and_u(s)['RU']), [1, 2, 3]) self.assertRaises(TypeError, r1.insert, s2, [1, 2, 4])
def testCanAddADeviceToMultipleAdjacentUs(self): """ you should be able to add a device to multiple adjacent RUs """ r1, r2 = [clusto.get_by_name(r) for r in ['r1','r2']] s1 = BasicServer('s1') s2 = BasicServer('s2') r1.insert(s1, [1,2,3]) clusto.flush() s = clusto.get_by_name('s1') self.assertEqual(sorted(BasicRack.get_rack_and_u(s)['RU']), [1,2,3]) self.assertRaises(TypeError, r1.insert, s2, [1,2,4])
def createRack(datacenter, rackprefix): try: clusto.begin_transaction() r = BasicRack(rackprefix) pwr = BasicPowerStrip(rackprefix + '-pwr1', withslave=True) sw = BasicNetworkSwitch(rackprefix + '-sw1') sw.connect_ports('nic-eth', 48, pwr, 1) pwr.connect_ports('pwr-nema-5', 1, sw, 1) r.insert(pwr, [1, 2, 3, 4]) r.insert(sw, [5]) for i in range(20): s = BasicServer(rackprefix + '-s' + '%02d' % i) r.insert(s, [6 + i]) s.connect_ports('nic-eth', 1, sw, i + 1) s.connect_ports('pwr-nema-5', 1, pwr, i + 2) clusto.commit() except Exception, x: clusto.rollback_transaction() raise x
def testRenameWithProperties(self): rack1 = BasicRack('rack1') rack1.set_attr(key='maxu', subkey='property', value=48) for x in range(3): rack1.add_attr(key='foo', subkey='bar', value=1, number=None) clusto.rename('rack1', 'rack2') rack2 = clusto.get_by_name('rack2') self.assertEqual( rack2.attrs(key='maxu', subkey='property')[0].value, 48) self.assertEqual(len(rack2.attrs(key='maxu')), 1) self.assertEqual(len(rack2.attrs(key='foo', subkey='bar')), 3)
def createRack(datacenter, rackprefix): try: clusto.begin_transaction() r = BasicRack(rackprefix) pwr = BasicPowerStrip(rackprefix+'-pwr1', withslave=True) sw = BasicNetworkSwitch(rackprefix+'-sw1') sw.connect_ports('nic-eth', 48, pwr, 1) pwr.connect_ports('pwr-nema-5', 1, sw, 1) r.insert(pwr, [1,2,3,4]) r.insert(sw, [5]) for i in range(20): s=BasicServer(rackprefix+'-s'+'%02d'%i) r.insert(s, [6+i]) s.connect_ports('nic-eth', 1, sw, i+1) s.connect_ports('pwr-nema-5', 1, pwr, i+2) clusto.commit() except Exception, x: clusto.rollback_transaction() raise x
def testSettingUpServer(self): from clusto.drivers import SimpleEntityNameManager servernames = SimpleEntityNameManager('servernames', basename='server', digits=4) newserver = servernames.allocate(BasicServer) sw = clusto.get_by_name('sw1') p1 = clusto.get_by_name('p1') r = clusto.get_by_name('r1') self.assertEqual('server0001', newserver.name) self.assertRaises(TypeError, r.insert, newserver, 1) r.insert(newserver, 2) p1.connect_ports('pwr-nema-5', 1, newserver, 1) sw.connect_ports('nic-eth', 1, newserver, 1) sw.connect_ports('nic-eth', 3, p1, 1) self.assertEqual(BasicRack.get_rack_and_u(newserver)['rack'], r) ipman = IPManager('subnet-10.0.0.1', netmask='255.255.255.0', baseip='10.0.0.1') newserver.bind_ip_to_osport('10.0.0.2', 'eth0', porttype='nic-eth', portnum=1) ipvals = newserver.attrs(value='10.0.0.2') self.assertEqual(len(ipvals), 1) self.assertEqual(ipvals[0].value, '10.0.0.2') self.assertEqual(clusto.get_by_attr('ip', '10.0.0.2'), [newserver]) aserver = servernames.allocate(BasicServer) ipattr = ipman.allocate(aserver) aserver.bind_ip_to_osport(ipattr.value, 'eth0', porttype='nic-eth', portnum=1) ip = aserver.attr_values(ipattr.key, number=ipattr.number, subkey=ipattr.subkey) self.assertEqual(aserver.get_port_attr('nic-eth', 1, 'osportname'), 'eth0') self.assertEqual(len(aserver.attrs(subkey='osportname', value='eth0')), 2) self.assertEqual( aserver.attrs( IPManager._attr_name, subkey='ipstring', number=aserver.attrs(IPManager._attr_name, subkey='osportname', value='eth0')[0].number, )[0].value, '10.0.0.1') ipattr2 = ipman.allocate(aserver) self.assertEqual(sorted(aserver.get_ips()), sorted(['10.0.0.1', '10.0.0.3']))
def testSettingUpServer(self): from clusto.drivers import SimpleEntityNameManager servernames = SimpleEntityNameManager('servernames', basename='server', digits=4 ) newserver = servernames.allocate(BasicServer) sw = clusto.get_by_name('sw1') p1 = clusto.get_by_name('p1') r = clusto.get_by_name('r1') self.assertEqual('server0001', newserver.name) self.assertRaises(TypeError, r.insert, newserver, 1) r.insert(newserver,2) p1.connect_ports('pwr-nema-5', 1, newserver, 1) sw.connect_ports('nic-eth', 1, newserver, 1) sw.connect_ports('nic-eth', 3, p1, 1) self.assertEqual(BasicRack.get_rack_and_u(newserver)['rack'], r) ipman = IPManager('subnet-10.0.0.1', netmask='255.255.255.0', baseip='10.0.0.1') newserver.bind_ip_to_osport('10.0.0.2', 'eth0', porttype='nic-eth', portnum=1) ipvals = newserver.attrs(value='10.0.0.2') self.assertEqual(len(ipvals), 1) self.assertEqual(ipvals[0].value, '10.0.0.2') self.assertEqual(clusto.get_by_attr('ip', '10.0.0.2'), [newserver]) aserver = servernames.allocate(BasicServer) ipattr = ipman.allocate(aserver) aserver.bind_ip_to_osport(ipattr.value, 'eth0', porttype='nic-eth', portnum=1) ip = aserver.attr_values(ipattr.key, number=ipattr.number, subkey=ipattr.subkey) self.assertEqual(aserver.get_port_attr('nic-eth', 1, 'osportname'), 'eth0') self.assertEqual(len(aserver.attrs(subkey='osportname', value='eth0')), 2) self.assertEqual(aserver.attrs(IPManager._attr_name, subkey='ipstring', number=aserver.attrs(IPManager._attr_name, subkey='osportname', value='eth0')[0].number, )[0].value, '10.0.0.1') ipattr2 = ipman.allocate(aserver) self.assertEqual(sorted(aserver.get_ips()), sorted(['10.0.0.1', '10.0.0.3']))
def data(self): r1 = BasicRack('r1') r2 = BasicRack('r2') clusto.flush()