Ejemplo n.º 1
0
    def test_01(s):
        keys = MapiClient(s.url, s.creds).ssl_keys
        s.assertEqual(len(keys), 0)

        key =u'-----BEGIN CERTIFICATE-----\r\nMIID/zCCAuegAwIBAgIJANK8J6AYFS5MMA0GCSqGSIb3DQEBCwUAMIGVMQswCQYD\r\nVQQGEwJVUzEPMA0GA1UECAwGT3JlZ29uMREwDwYDVQQHDAhQb3J0bGFuZDEhMB8G\r\nA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRAwDgYDVQQLDAdmb28ub3Jn\r\nMRAwDgYDVQQDDAdmb28ub3JnMRswGQYJKoZIhvcNAQkBFgxub25lQGZvby5jb20w\r\nHhcNMTUwOTA0MTM0MjI4WhcNMTYwOTAzMTM0MjI4WjCBlTELMAkGA1UEBhMCVVMx\r\nDzANBgNVBAgMBk9yZWdvbjERMA8GA1UEBwwIUG9ydGxhbmQxITAfBgNVBAoMGElu\r\ndGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEQMA4GA1UECwwHZm9vLm9yZzEQMA4GA1UE\r\nAwwHZm9vLm9yZzEbMBkGCSqGSIb3DQEJARYMbm9uZUBmb28uY29tMIIBIjANBgkq\r\nhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuMSV3ftRS99XBUjDdaKq7sSYrcGpg/yq\r\nWdQelJJ5Htn9CJNE8aKrZQwniVtLXB4Q5Bx0xm6ffIQkO3K8gMZcgkEBJFJILD/i\r\nGchkXvQE8m4gMkwllimC14DYEcrRA12hpNpUutnKUx/6KGQaptd/zRPcDRatO9SK\r\n33uX25AnpnEqH7oky4VoaubHQdNlvAgXLJcXEWGgGga/SVRPkL8cVoXMdZkN9n7L\r\niZW9E5rfCISfAE6jIpLYzWQmXuYChI312pq4JMG7iOQL+1WjfssN6t6xMjGlw1V5\r\nI54NiqHjWkt4ZBrGW8Ve781AphLWOlzP55lMxgvbU8u5fXWvYTxLiQIDAQABo1Aw\r\nTjAdBgNVHQ4EFgQU1K7Ak+Qdew5bDguVj7AUvsGUfEkwHwYDVR0jBBgwFoAU1K7A\r\nk+Qdew5bDguVj7AUvsGUfEkwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC\r\nAQEAZfXb0mHrOChfP84EFn3fS77ADuMu5UFe4rvkhOshQD4thhsqXweOwu9g7AM8\r\nyuEYKvBiBI8HsUxGU++yTf0Nj2nHaRhyPu3tx3h4I0m187dItSut8rj80fzVXAKE\r\n8wK8AWkT5rRToDoMjA51yPD165EYYvCKBbN7AJYAYSKSOGn3r72G+8F1MyN3KgsO\r\nB+gIaXTOAouMe3PXHarF1J3Te9z2McV+THukRgm28RolbiqTTESxxz7GUxx+sfps\r\nzy4omSW+lPIBZ3xwHKmWRx9YfWj4B1tAqPZrrUqEjr5mc6gEcwGtVCaFSGQRBf6X\r\n2V86zNlxIyXLlCvisS0wVS2iSA==\r\n-----END CERTIFICATE-----\r\n'
        keys.new(key)
        s.assertEqual(len(keys), 1)
        s.assertEqual(keys[0]['key'], key)

        del(keys[0])
        s.assertEqual(len(keys), 0)
Ejemplo n.º 2
0
    def test_01(s):
        keys = MapiClient(s.url, s.creds).ssl_keys
        s.assertEqual(len(keys), 0)

        key = u'-----BEGIN CERTIFICATE-----\r\nMIID/zCCAuegAwIBAgIJANK8J6AYFS5MMA0GCSqGSIb3DQEBCwUAMIGVMQswCQYD\r\nVQQGEwJVUzEPMA0GA1UECAwGT3JlZ29uMREwDwYDVQQHDAhQb3J0bGFuZDEhMB8G\r\nA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRAwDgYDVQQLDAdmb28ub3Jn\r\nMRAwDgYDVQQDDAdmb28ub3JnMRswGQYJKoZIhvcNAQkBFgxub25lQGZvby5jb20w\r\nHhcNMTUwOTA0MTM0MjI4WhcNMTYwOTAzMTM0MjI4WjCBlTELMAkGA1UEBhMCVVMx\r\nDzANBgNVBAgMBk9yZWdvbjERMA8GA1UEBwwIUG9ydGxhbmQxITAfBgNVB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
        keys.new(key)
        s.assertEqual(len(keys), 1)
        s.assertEqual(keys[0]['key'], key)

        del (keys[0])
        s.assertEqual(len(keys), 0)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
 def tearDown(s):
     # Cleanup (delete) any zones that were created during testing. The only
     # zone that is not created by testing is the 'default' zone.
     #
     zones = MapiClient(s.url, s.creds).zones
     for z in zones:
         if z.name == 'default':
             continue
         del (zones[z.name])
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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'])
Ejemplo n.º 9
0
    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))
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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))
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 def test_subversion(s):
     subversion = MapiClient(s.url, s.creds).version.subversion
     s.assertEqual('trusty1', subversion)
Ejemplo n.º 18
0
    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