def test_version(s): version = MapiClient(s.url, s.creds).version.version m = re.match(r'\d+.\d+.\d+\+bzr\d+\-\d+ubuntu\d+', version) s.assertIsNotNone(m, msg='%s does not match the regular expression' % version)
def test_01(s): nodes = MapiClient(s.url, s.creds).nodes s.assertEqual(len(nodes), 4, msg='Expected 4 nodes but found %d instead.' % len(nodes)) node = nodes[0] s.assertIsNotNone(node) for node in nodes: s.assertIsNotNone(node) result = nodes.deployment_status( [nodes[0]['system_id'], nodes[1]['system_id']]) s.assertIs(type(result), dict) s.assertEqual(len(result), 2, msg='Expected 2 nodes but found %d instead.' % len(nodes)) s.assertTrue(nodes[0]['system_id'] in result) s.assertTrue(nodes[1]['system_id'] in result) s.assertTrue( result[nodes[0]['system_id']] in ['Deployed', 'Not in deployment']) s.assertTrue( result[nodes[1]['system_id']] in ['Deployed', 'Not in deployment']) nodes[0].acquire() nodes[1].acquire() allocated = nodes.list_allocated() s.assertIs(type(allocated), Nodes) s.assertEqual(len(allocated), 2, msg='Expected 2 nodes but found %d instead.' % len(nodes)) nodes[0].release() nodes[1].release() params = nodes.power_parameters() s.assertTrue(len(params) > 0) result = nodes.accept([nodes[0]['system_id'], nodes[1]['system_id']]) nodes[0].release() nodes[1].release() result = nodes.accept_all() nodes[0].release() nodes[1].release() result = nodes.check_commissioning() print(json.dumps(result, sort_keys=True, indent=4))
def test_capabilities(s): capabilities = MapiClient(s.url, s.creds).version.capabilities s.assertTrue(len(capabilities) >= 3, msg='capabilities: %s' % capabilities) caps = [ 'networks-management', 'static-ipaddresses', 'ipv6-deployment-ubuntu' ] for c in caps: s.assertIn(c, capabilities)
def test_users(s): users = MapiClient(s.url, s.creds).users # There are 4 users defined on the maas server that I'm using for testing. # s.assertEqual(len(users), 4) #username, email, password, is_superuser print(len(users)) for user in users: s.assertIsNotNone(s.defined[user.username]) s.assertEqual(user.superuser, s.defined[user.username]['admin']) s.assertEqual(user.email, s.defined[user.username]['email'])
def test_01(s): nodes = MapiClient(s.url, s.creds).nodes s.assertEqual(len(nodes), 4, msg='Expected 4 nodes but found %d instead.' % len(nodes)) node = nodes[0] s.assertIsNotNone(node) vgs = node.volume_groups for vg in vgs: s.assertIsNotNone(vg) print(json.dumps(vg, sort_keys=True, indent=4))
def test_zones(s): zones = MapiClient(s.url, s.creds).zones # Should only be the default zone. # s.assertEqual(len(zones), 1) # Add one # zones['foo'] = 'bar' s.assertEqual(len(zones), 2) # Delete the one we just added # del (zones['foo']) s.assertEqual(len(zones), 1)
def test_zone(s): zones = MapiClient(s.url, s.creds).zones # Should only be the default zone. # s.assertEqual(len(zones), 1) # Add one # zones['foo'] = 'bar' s.assertEqual(len(zones), 2) for z in zones: if z.name == 'foo': s.assertEqual(z.name, 'foo') s.assertEqual(z.description, 'bar') s.assertIsNotNone(z.resource_uri)
def test_tags(s): tags = MapiClient(s.url, s.creds).tags s.assertIsNotNone(tags) # When we are starting out there shouldn't be any tags currently defined # on the MAAS server. # s.assertEqual(len(tags), 0) # Verify we can add a tag # tags.add( Tag(name='intel-gpu', comment='Machines which have an Intel display driver', definition='contains(//node[@id="display"]/vendor, "Intel")')) s.assertEqual(len(tags), 1) # Verify we can delete the tag that we just added. # tags.delete( Tag(name='intel-gpu', comment='Machines which have an Intel display driver', definition='contains(//node[@id="display"]/vendor, "Intel")')) s.assertEqual(len(tags), 0)
def test_subversion(s): subversion = MapiClient(s.url, s.creds).version.subversion s.assertEqual('trusty1', subversion)
def test_01(s): try: nodes = MapiClient(s.url, s.creds).nodes s.assertEqual(len(nodes), 4, msg='Expected 4 nodes but found %d instead.' % len(nodes)) node = nodes[0] s.assertIsNotNone(node) for node in nodes: if node['hostname'] == 'nuc1.maas': break # node.power_state # pstate = node.power_state s.assertEqual(pstate, 'on') print(pstate) # node.details # details = node.details s.assertIsNotNone(details) # node.power_parameters # params = node.power_parameters s.assertIsNotNone(params) s.assertEqual(params['power_address'], '10.10.10.100') s.assertEqual(params['power_pass'], '1Pa**word') s.assertEqual(params['mac_address'], 'ec:a8:6b:fa:91:64') node.abort() try: result = node.abort() s.assertTrue( False, 'The node.abort() should have thrown an exception.') except MaasApiNodeStateReady as e: s.assertTrue(True) # node.commission() # result = node.commission() s.assertTrue(type(result), Node) #print(json.dumps(node, sort_keys=True, indent=4)) # node.mark_broken() # result = node.mark_broken(description='MAAS Api Testing') s.assertTrue(type(result), Node) #print(json.dumps(result, sort_keys=True, indent=4)) sleep(1) # node.mark_fixed() # result = node.mark_fixed() s.assertTrue(type(result), Node) #print(json.dumps(result, sort_keys=True, indent=4)) # node.release() # #print(json.dumps(node, sort_keys=True, indent=4)) result = node.release() s.assertTrue(type(result), Node) #print(json.dumps(result, sort_keys=True, indent=4)) # node.claim_sticky_ip_address() # try: result = node.claim_sticky_ip_address( mac_address='12:34:56:78:ab:cd', requested_address='10.10.11.111') s.assertTrue( False, 'Should have raised a MaasApiNodeBadMACAddress exception.') except MaasApiNodeBadMACAddress as e: s.assertTrue(True) # sleep(2) # result = node.claim_sticky_ip_address(requested_address='10.10.11.111') # print(json.dumps(result, sort_keys=True, indent=4)) # sleep(2) # # node.release_sticky_ip_address() # # # result = node.release_sticky_ip_address() # print(json.dumps(result, sort_keys=True, indent=4)) # node.acquire() # result = node.acquire() s.assertIs(type(result), Node) #print('acquire ______________________________') #print(json.dumps(result, sort_keys=True, indent=4)) sleep(2) # node.release() # result = node.release() s.assertIs(type(result), Node) #print('release ______________________________') #print(json.dumps(result, sort_keys=True, indent=4)) # node.start() # try: result = node.start() s.assertTrue( False, 'Should have raised a MaasApiNodeNotAcquired exception.') except MaasApiNodeNotAcquired as e: s.assertTrue(True) except MaasApiHttpInternalServerError as e: print(e.status) print(e.message) s.assertTrue(False) result = node.acquire() s.assertIs(type(result), Node) sleep(2) try: result = node.start() s.assertIs(type(result), Node) except MaasApiNodeNotAcquired as e: s.assertTrue(True) except MaasApiHttpInternalServerError as e: print(e.status) print(e.message) s.assertTrue(False) except MaasApiUnknownError as e: print(e.status) print(e.message) raise e
def tearDown(s): # Cleanup (delete) any tags that were created during testing. # tags = MapiClient(s.url, s.creds).tags for t in tags: tags.delete(t)
def test_tag(s): mc = MapiClient(s.url, s.creds) tags = mc.tags s.assertIsNotNone(tags) # Add two tags and verify we can get them back. # tags.new( name='intel-gpu', comment='Intel GPUs', definition='//node[@id="display"]/vendor = "Intel Corporation"') tags.new( name='intel-cpu', comment='Intel CPUs', definition='//node[@class="processor"]/vendor = "Intel Corp."') tags.new(name='tester', comment='Simple tag') tags.new(name='badger') sleep(1) # Hack s.assertEqual(len(tags), 2) tag = tags[0] s.assertIsNotNone(tag) s.assertEqual(tag.name, 'intel-gpu') s.assertEqual(tag.comment, 'Intel GPUs') s.assertEqual(tag.definition, '//node[@id="display"]/vendor = "Intel Corporation"') tag = tags[1] s.assertIsNotNone(tag) s.assertEqual(tag.name, 'intel-cpu') s.assertEqual(tag.comment, 'Intel CPUs') s.assertEqual(tag.definition, '//node[@class="processor"]/vendor = "Intel Corp."') # On the MAAS server that I'm using for testing there are 2 Intel NUCs defined. Make # sure those both got tagged. # nodes = tag.nodes s.assertEqual(len(nodes), 2) s.assertIn(nodes[0]['hostname'], ['nuc1.maas', 'nuc2.maas'], msg='Expected \'nuc[12].maas\' but got \'%s\' instead.' % nodes[0]['hostname']) s.assertIn(nodes[1]['hostname'], ['nuc1.maas', 'nuc2.maas'], msg='Expected \'nuc[12].maas\' but got \'%s\' instead.' % nodes[1]['hostname']) # Run a rebuild on both tags just to see if anything blows up. # tags[0].rebuild() tags[1].rebuild() # Update the first tag and verify that it got updated. # tags[0].update(name='iNtEl-GpU', comment='This is a test') sleep(1) # Hack tags = mc.tags # Hack - The update operated on an individual tag but no way to mark the # internal s.__tags as dirty. s.assertEqual(tags[1].name, 'iNtEl-GpU') # Test adding and removing nodes from a tag. # tags = mc.tags tag = tags[0] nodes = tag.nodes s.assertEqual(len(nodes), 2) tag.remove_nodes([nodes[0]['system_id']]) sleep(1) # Hack tags = mc.tags tag = tags[0] nodes = tag.nodes for n in nodes: print(n['system_id']) s.assertEqual(len(nodes), 1)