Example #1
0
    def test__get_nodes_mac_addresses(self):
        #stop all the mocks because this test does not use them
        self.get_mac_addr_patcher.stop()
        self.get_mac_addr_mock = None
        self.get_conn_patcher.stop()
        self.get_conn_mock = None

        ports = []
        ports.append(self.port)
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    node_id=self.node['id'],
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    node_id=self.node['id'],
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire(self.context, [self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(sorted([p.address for p in ports]), sorted(node_macs))
Example #2
0
    def test_replace_address_already_exist(self):
        address = '11:22:33:AA:BB:CC'
        pdict = dbutils.get_test_port(address=address,
                                      uuid=uuidutils.generate_uuid())
        self.post_json('/ports', pdict)

        pdict = dbutils.get_test_port()
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/address',
                                     'value': address, 'op': 'replace'}],
                                     expect_errors=True)
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 400)
        self.assertTrue(response.json['error_message'])
Example #3
0
    def test__get_nodes_mac_addresses(self):
        ports = []
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(id=6, address="aa:bb:cc", uuid="bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53")
            )
        )
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(id=7, address="dd:ee:ff", uuid="4fc26c0b-03f2-4d2e-ae87-c02d7f33c234")
            )
        )

        with task_manager.acquire([self.node["uuid"]]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(node_macs, ["aa:bb:cc", "dd:ee:ff"])
Example #4
0
 def test_update_port_duplicated_address(self):
     self.dbapi.create_port(self.p)
     address1 = self.p["address"]
     address2 = "aa-bb-cc-11-22-33"
     p2 = db_utils.get_test_port(id=123, uuid=ironic_utils.generate_uuid(), node_id=self.n.id, address=address2)
     self.dbapi.create_port(p2)
     self.assertRaises(exception.MACAlreadyExists, self.dbapi.update_port, p2["id"], {"address": address1})
Example #5
0
    def test_remove_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        pdict = dbutils.get_test_port(extra=extra,
                                   address="aa:bb:cc:dd:ee:ff",
                                   uuid=utils.generate_uuid())
        self.dbapi.create_port(pdict)

        # Removing one item from the collection
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/extra/foo2', 'op': 'remove'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
        result = self.get_json('/ports/%s' % pdict['uuid'])
        extra.pop("foo2")
        self.assertEqual(extra, result['extra'])

        # Removing the collection
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/extra', 'op': 'remove'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
        result = self.get_json('/ports/%s' % pdict['uuid'])
        self.assertEqual({}, result['extra'])

        # Assert nothing else was changed
        self.assertEqual(pdict['uuid'], result['uuid'])
        self.assertEqual(pdict['address'], result['address'])
Example #6
0
 def test_delete_port_byaddress(self):
     pdict = dbutils.get_test_port()
     response = self.delete('/ports/%s' % pdict['address'],
                            expect_errors=True)
     self.assertEqual(400, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertIn(pdict['address'], response.json['error_message'])
Example #7
0
    def setUp(self):
        super(SSHDriverTestCase, self).setUp()
        self.context = context.get_admin_context()
        mgr_utils.mock_the_extension_manager(driver="fake_ssh")
        self.driver = driver_factory.get_driver("fake_ssh")
        n = db_utils.get_test_node(
                driver='fake_ssh',
                driver_info=INFO_DICT)
        self.dbapi = dbapi.get_instance()
        self.node = self.dbapi.create_node(n)
        self.port = self.dbapi.create_port(db_utils.get_test_port(
                                                         node_id=self.node.id))
        self.sshclient = paramiko.SSHClient()

        #setup these mocks because most tests use them
        self.parse_drv_info_patcher = mock.patch.object(ssh,
                                                        '_parse_driver_info')
        self.parse_drv_info_mock = None
        self.get_mac_addr_patcher = mock.patch.object(
                ssh,
                '_get_nodes_mac_addresses')
        self.get_mac_addr_mock = self.get_mac_addr_patcher.start()
        self.get_conn_patcher = mock.patch.object(ssh, '_get_connection')
        self.get_conn_mock = self.get_conn_patcher.start()

        def stop_patchers():
            if self.parse_drv_info_mock:
                self.parse_drv_info_patcher.stop()
            if self.get_mac_addr_mock:
                self.get_mac_addr_patcher.stop()
            if self.get_conn_mock:
                self.get_conn_patcher.stop()

        self.addCleanup(stop_patchers)
Example #8
0
 def test_create_port_duplicated_address(self):
     self.dbapi.create_port(self.p)
     dup_address = self.p['address']
     p2 = db_utils.get_test_port(id=123, uuid=ironic_utils.generate_uuid(),
                              node_id=self.n.id, address=dup_address)
     self.assertRaises(exception.MACAlreadyExists,
                       self.dbapi.create_port, p2)
Example #9
0
 def test_create_port_duplicated_uuid(self):
     self.dbapi.create_port(self.p)
     p2 = db_utils.get_test_port(id=123, uuid=self.p['uuid'],
                                 node_id=self.n.id,
                                 address='aa-bb-cc-33-11-22')
     self.assertRaises(exception.PortAlreadyExists,
                       self.dbapi.create_port, p2)
Example #10
0
    def test_remove_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        pdict = dbutils.get_test_port(extra=extra,
                                      address="AA:BB:CC:DD:EE:FF",
                                      uuid=uuidutils.generate_uuid())
        self.post_json('/ports', pdict)

        # Removing one item from the collection
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/extra/foo2', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/ports/%s' % pdict['uuid'])
        extra.pop("foo2")
        self.assertEqual(result['extra'], extra)

        # Removing the collection
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/extra', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/ports/%s' % pdict['uuid'])
        self.assertEqual(result['extra'], {})

        # Assert nothing else was changed
        self.assertEqual(result['uuid'], pdict['uuid'])
        self.assertEqual(result['address'], pdict['address'])
Example #11
0
 def test_create_port_generate_uuid(self):
     pdict = dbutils.get_test_port()
     del pdict['uuid']
     self.post_json('/ports', pdict)
     result = self.get_json('/ports/%s' % pdict['address'])
     self.assertEqual(pdict['address'], result['address'])
     self.assertTrue(uuidutils.is_uuid_like(result['uuid']))
Example #12
0
 def test_destroy_port_on_reserved_node(self):
     n = self.dbapi.create_node(self.n)
     p = self.dbapi.create_port(utils.get_test_port(node_id=n['id']))
     uuid = n['uuid']
     self.dbapi.reserve_nodes('fake-reservation', [uuid])
     self.assertRaises(exception.NodeLocked,
                       self.dbapi.destroy_port, p['id'])
Example #13
0
 def test_ports_subresource_noid(self):
     node = obj_utils.create_test_node(self.context)
     pdict = dbutils.get_test_port(node_id=node.id)
     self.dbapi.create_port(pdict)
     # No node id specified
     response = self.get_json('/nodes/ports', expect_errors=True)
     self.assertEqual(400, response.status_int)
Example #14
0
 def test_post_ports_subresource(self):
     ndict = dbutils.get_test_node()
     self.post_json('/nodes', ndict)
     pdict = dbutils.get_test_port()
     response = self.post_json('/nodes/ports', pdict,
                               expect_errors=True)
     self.assertEqual(response.status_int, 403)
Example #15
0
 def test_links(self):
     uuid = uuidutils.generate_uuid()
     ndict = dbutils.get_test_port(id=1, uuid=uuid)
     self.dbapi.create_port(ndict)
     data = self.get_json('/ports/1')
     self.assertIn('links', data.keys())
     self.assertEqual(len(data['links']), 2)
     self.assertIn(uuid, data['links'][0]['href'])
Example #16
0
 def test_create_port_with_hyphens_delimiter(self):
     pdict = dbutils.get_test_port()
     colonsMAC = pdict['address']
     hyphensMAC = colonsMAC.replace(':', '-')
     pdict['address'] = hyphensMAC
     self.assertRaises(webtest.app.AppError,
                       self.post_json,
                       '/ports', pdict)
Example #17
0
    def setUp(self):
        # This method creates a port for every test and
        # replaces a test for creating a port.
        super(DbPortTestCase, self).setUp()
        self.dbapi = dbapi.get_instance()

        self.n = utils.get_test_node()
        self.p = utils.get_test_port()
 def test_update_port_on_reserved_node(self):
     p = self.dbapi.create_port(utils.get_test_port(node_id=self.n['id']))
     uuid = self.n['uuid']
     self.dbapi.reserve_nodes('fake-reservation', [uuid])
     new_address = 'ff.ee.dd.cc.bb.aa'
     self.assertRaises(exception.NodeLocked,
                       self.dbapi.update_port, p['id'],
                       {'address': new_address})
Example #19
0
 def test_delete_port_byaddress(self):
     pdict = dbutils.get_test_port()
     self.delete('/ports/%s' % pdict['address'])
     response = self.get_json('/ports/%s' % pdict['uuid'],
                              expect_errors=True)
     self.assertEqual(response.status_int, 404)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #20
0
 def test_nodes_subresource_noid(self):
     ndict = dbutils.get_test_node()
     self.dbapi.create_node(ndict)
     pdict = dbutils.get_test_port(node_id=ndict['id'])
     self.dbapi.create_port(pdict)
     # No node id specified
     response = self.get_json('/nodes/ports', expect_errors=True)
     self.assertEqual(response.status_int, 400)
 def test_get_port_list(self):
     uuids = []
     for i in xrange(1, 6):
         n = utils.get_test_port(id=i, uuid=uuidutils.generate_uuid())
         self.dbapi.create_port(n)
         uuids.append(unicode(n['uuid']))
     res = self.dbapi.get_port_list()
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Example #22
0
 def test_add_singular(self):
     pdict = dbutils.get_test_port()
     response = self.patch_json('/ports/%s' % pdict['uuid'],
                                [{'path': '/foo', 'value': 'bar',
                                  'op': 'add'}],
                                expect_errors=True)
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.status_int, 400)
     self.assertTrue(response.json['error_message'])
Example #23
0
    def test__get_nodes_mac_addresses(self):
        ports = []
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire([self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(node_macs, ['aa:bb:cc', 'dd:ee:ff'])
Example #24
0
 def test_update_byaddress_with_hyphens_delimiter(self):
     pdict = dbutils.get_test_port()
     pdict['address'] = pdict['address'].replace(':', '-')
     self.assertRaises(webtest.app.AppError,
                       self.patch_json,
                       '/ports/%s' % pdict['address'],
                       [{'path': '/extra/foo',
                       'value': 'bar',
                       'op': 'add'}])
Example #25
0
 def test_delete_port_byid(self):
     pdict = dbutils.get_test_port()
     self.delete('/ports/%s' % pdict['uuid'])
     response = self.get_json('/ports/%s' % pdict['uuid'],
                              expect_errors=True)
     # TODO(yuriyz): change to 404 (bug 1200517)
     self.assertEqual(response.status_int, 500)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #26
0
 def test_get_port_list(self):
     uuids = []
     for i in range(1, 6):
         n = db_utils.get_test_port(id=i, uuid=ironic_utils.generate_uuid(), address="52:54:00:cf:2d:3%s" % i)
         self.dbapi.create_port(n)
         uuids.append(six.text_type(n["uuid"]))
     res = self.dbapi.get_port_list()
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Example #27
0
 def test_detail(self):
     pdict = dbutils.get_test_port()
     port = self.dbapi.create_port(pdict)
     data = self.get_json('/ports/detail')
     self.assertEqual(port['uuid'], data['ports'][0]["uuid"])
     self.assertIn('extra', data['ports'][0])
     self.assertIn('node_uuid', data['ports'][0])
     # never expose the node_id
     self.assertNotIn('node_id', data['ports'][0])
Example #28
0
 def test_get_one(self):
     pdict = dbutils.get_test_port()
     port = self.dbapi.create_port(pdict)
     data = self.get_json('/ports/%s' % port['uuid'])
     self.assertEqual(port['uuid'], data['uuid'])
     self.assertIn('extra', data)
     self.assertIn('node_uuid', data)
     # never expose the node_id
     self.assertNotIn('node_id', data)
Example #29
0
 def test_update_byaddress(self):
     pdict = dbutils.get_test_port()
     extra = {'foo': 'bar'}
     response = self.patch_json('/ports/%s' % pdict['address'],
                                {'extra': extra})
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.status_code, 200)
     result = self.get_json('/ports/%s' % pdict['uuid'])
     self.assertEqual(result['extra'], extra)
Example #30
0
 def test_port_by_address_invalid_address_format(self):
     pdict = dbutils.get_test_port()
     self.dbapi.create_port(pdict)
     invalid_address = 'invalid-mac-format'
     response = self.get_json('/ports?address=%s' % invalid_address,
                              expect_errors=True)
     self.assertEqual(400, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertIn(invalid_address, response.json['error_message'])
Example #31
0
 def test_get_port_list(self):
     uuids = []
     for i in range(1, 6):
         n = db_utils.get_test_port(id=i, uuid=ironic_utils.generate_uuid(),
                                 address='52:54:00:cf:2d:3%s' % i)
         self.dbapi.create_port(n)
         uuids.append(six.text_type(n['uuid']))
     res = self.dbapi.get_port_list()
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Example #32
0
 def test_update_port_duplicated_address(self):
     self.dbapi.create_port(self.p)
     address1 = self.p['address']
     address2 = 'aa-bb-cc-11-22-33'
     p2 = db_utils.get_test_port(id=123, uuid=ironic_utils.generate_uuid(),
                              node_id=self.n.id, address=address2)
     self.dbapi.create_port(p2)
     self.assertRaises(exception.MACAlreadyExists,
                       self.dbapi.update_port, p2['id'],
                       {'address': address1})
Example #33
0
    def test_ports_get_destroyed_after_destroying_a_node_by_uuid(self):
        n = self._create_test_node()
        node_id = n['id']

        p = utils.get_test_port(node_id=node_id)
        p = self.dbapi.create_port(p)

        self.dbapi.destroy_node(n['uuid'])

        self.assertRaises(exception.PortNotFound, self.dbapi.get_port, p.id)
Example #34
0
 def test_links(self):
     uuid = utils.generate_uuid()
     ndict = dbutils.get_test_port(id=1, uuid=uuid)
     self.dbapi.create_port(ndict)
     data = self.get_json('/ports/%s' % uuid)
     self.assertIn('links', data.keys())
     self.assertEqual(2, len(data['links']))
     self.assertIn(uuid, data['links'][0]['href'])
     self.assertTrue(self.validate_link(data['links'][0]['href']))
     self.assertTrue(self.validate_link(data['links'][1]['href']))
Example #35
0
def get_test_port(ctxt, **kw):
    """Return a Port object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_port = db_utils.get_test_port(**kw)
    port = objects.Port(ctxt)
    for key in db_port:
        setattr(port, key, db_port[key])
    return port
Example #36
0
    def test__get_nodes_mac_addresses(self):
        ports = []
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=6,
                    node_id=self.node['id'],
                    address='aa:bb:cc',
                    uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53')))
        ports.append(
            self.dbapi.create_port(
                db_utils.get_test_port(
                    id=7,
                    node_id=self.node['id'],
                    address='dd:ee:ff',
                    uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234')))

        with task_manager.acquire([self.node['uuid']]) as task:
            node_macs = ssh._get_nodes_mac_addresses(task, self.node)
        self.assertEqual(node_macs, ['aa:bb:cc', 'dd:ee:ff'])
Example #37
0
 def test_links(self):
     uuid = utils.generate_uuid()
     ndict = dbutils.get_test_port(id=1, uuid=uuid)
     self.dbapi.create_port(ndict)
     data = self.get_json('/ports/%s' % uuid)
     self.assertIn('links', data.keys())
     self.assertEqual(2, len(data['links']))
     self.assertIn(uuid, data['links'][0]['href'])
     for l in data['links']:
         bookmark = l['rel'] == 'bookmark'
         self.assertTrue(self.validate_link(l['href'], bookmark=bookmark))
Example #38
0
 def test__get_nodes_mac_addresses(self):
     ports = []
     ports.append(self.port)
     ports.append(
         self.dbapi.create_port(
             db_utils.get_test_port(
                 id=6,
                 address='aa:bb:cc',
                 uuid='bb43dc0b-03f2-4d2e-ae87-c02d7f33cc53',
                 node_id='123')))
     ports.append(
         self.dbapi.create_port(
             db_utils.get_test_port(
                 id=7,
                 address='dd:ee:ff',
                 uuid='4fc26c0b-03f2-4d2e-ae87-c02d7f33c234',
                 node_id='123')))
     with task_manager.acquire(self.context, [self.node['uuid']]) as task:
         node_macs = pxe._get_node_mac_addresses(task, self.node)
     self.assertEqual(sorted(node_macs), sorted([p.address for p in ports]))
Example #39
0
 def setUp(self):
     super(SSHDriverTestCase, self).setUp()
     mgr_utils.mock_the_extension_manager(driver="fake_ssh")
     self.driver = driver_factory.get_driver("fake_ssh")
     self.node = obj_utils.create_test_node(
             self.context, driver='fake_ssh',
             driver_info=db_utils.get_test_ssh_info())
     self.dbapi = dbapi.get_instance()
     self.port = self.dbapi.create_port(db_utils.get_test_port(
                                                      node_id=self.node.id))
     self.sshclient = paramiko.SSHClient()
Example #40
0
    def setUp(self):
        super(TestPatch, self).setUp()
        ndict = dbutils.get_test_node()
        self.node = self.dbapi.create_node(ndict)
        pdict = dbutils.get_test_port(id=None)
        self.port = self.dbapi.create_port(pdict)

        p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
        self.mock_gtf = p.start()
        self.mock_gtf.return_value = 'test-topic'
        self.addCleanup(p.stop)
Example #41
0
    def test_port_by_address(self):
        address_template = "aa:bb:cc:dd:ee:f%d"
        for id_ in range(3):
            pdict = dbutils.get_test_port(id=id_,
                                          uuid=utils.generate_uuid(),
                                          address=address_template % id_)
            self.dbapi.create_port(pdict)

        target_address = address_template % 1
        data = self.get_json('/ports?address=%s' % target_address)
        self.assertThat(data['ports'], HasLength(1))
        self.assertEqual(target_address, data['ports'][0]['address'])
Example #42
0
    def test_replace_address_already_exist(self):
        pdict1 = dbutils.get_test_port(address='aa:aa:aa:aa:aa:aa',
                                       uuid=utils.generate_uuid(),
                                       id=None)
        self.dbapi.create_port(pdict1)

        pdict2 = dbutils.get_test_port(address='bb:bb:bb:bb:bb:bb',
                                       uuid=utils.generate_uuid(),
                                       id=None)
        self.dbapi.create_port(pdict2)

        response = self.patch_json('/ports/%s' % pdict1['uuid'],
                                   [{
                                       'path': '/address',
                                       'value': pdict2['address'],
                                       'op': 'replace'
                                   }],
                                   expect_errors=True)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(409, response.status_code)
        self.assertTrue(response.json['error_message'])
Example #43
0
    def test_many(self):
        ports = []
        for id in xrange(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=uuidutils.generate_uuid())
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports')
        self.assertEqual(len(ports), len(data['items']))

        uuids = [n['uuid'] for n in data['items']]
        self.assertEqual(ports.sort(), uuids.sort())
Example #44
0
    def test_clean_up_pxe_config(self, unlink_mock, rmtree_mock):
        address = "aa:aa:aa:aa:aa:aa"
        pdict = dbutils.get_test_port(node_uuid=self.node.uuid,
                                      address=address)
        self.dbapi.create_port(pdict)

        with task_manager.acquire(self.context, self.node.uuid) as task:
            pxe_utils.clean_up_pxe_config(task)

        unlink_mock.assert_called_once_with("/tftpboot/pxelinux.cfg/01-%s" %
                                            address.replace(':', '-'))
        rmtree_mock.assert_called_once_with(
            os.path.join(CONF.pxe.tftp_root, self.node.uuid))
Example #45
0
    def test_remove_mandatory_field(self):
        pdict = dbutils.get_test_port(address="AA:BB:CC:DD:EE:FF",
                                      uuid=utils.generate_uuid())
        self.dbapi.create_port(pdict)

        response = self.patch_json('/ports/%s' % pdict['uuid'], [{
            'path': '/address',
            'op': 'remove'
        }],
                                   expect_errors=True)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(400, response.status_code)
        self.assertTrue(response.json['error_message'])
Example #46
0
    def test_collection_links(self):
        ports = []
        for id in range(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=utils.generate_uuid(),
                                          address='52:54:00:cf:2d:3%s' % id)
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports/?limit=3')
        self.assertEqual(3, len(data['ports']))

        next_marker = data['ports'][-1]['uuid']
        self.assertIn(next_marker, data['next'])
Example #47
0
    def test_many(self):
        ports = []
        for id in range(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=utils.generate_uuid(),
                                          address='52:54:00:cf:2d:3%s' % id)
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports')
        self.assertEqual(len(ports), len(data['ports']))

        uuids = [n['uuid'] for n in data['ports']]
        self.assertEqual(ports.sort(), uuids.sort())
Example #48
0
    def test_collection_links(self):
        ports = []
        for id in xrange(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=uuidutils.generate_uuid())
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports/?limit=3')
        self.assertEqual(data['type'], 'port')
        self.assertEqual(len(data['items']), 3)

        next_marker = data['items'][-1]['uuid']
        next_link = [l['href'] for l in data['links'] if l['rel'] == 'next'][0]
        self.assertIn(next_marker, next_link)
Example #49
0
 def test_update_address_invalid_format(self):
     pdict = dbutils.get_test_port(address="AA:BB:CC:DD:EE:FF",
                                   uuid=utils.generate_uuid())
     self.dbapi.create_port(pdict)
     response = self.patch_json('/ports/%s' % pdict['uuid'],
                                [{
                                    'path': '/address',
                                    'value': 'invalid-format',
                                    'op': 'replace'
                                }],
                                expect_errors=True)
     self.assertEqual(400, response.status_int)
     self.assertEqual('application/json', response.content_type)
     self.assertTrue(response.json['error_message'])
Example #50
0
def get_test_port(ctxt, **kw):
    """Return a Port object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_port = db_utils.get_test_port(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_port['id']
    port = objects.Port(ctxt)
    for key in db_port:
        setattr(port, key, db_port[key])
    return port
Example #51
0
    def test_refresh(self):
        uuid = self.fake_port['uuid']
        returns = [
            self.fake_port,
            utils.get_test_port(address="c3:54:00:cf:2d:40")
        ]
        expected = [mock.call(uuid), mock.call(uuid)]
        with mock.patch.object(self.dbapi, 'get_port_by_uuid',
                               side_effect=returns, autospec=True) \
                as mock_get_port:
            p = objects.Port.get_by_uuid(self.context, uuid)
            self.assertEqual("52:54:00:cf:2d:31", p.address)
            p.refresh()
            self.assertEqual("c3:54:00:cf:2d:40", p.address)

            self.assertEqual(expected, mock_get_port.call_args_list)
Example #52
0
 def setUp(self):
     super(PXEDriverTestCase, self).setUp()
     self.context = context.get_admin_context()
     self.context.auth_token = '4562138218392831'
     self.temp_dir = tempfile.mkdtemp()
     self.config(tftp_root=self.temp_dir, group='pxe')
     self.temp_dir = tempfile.mkdtemp()
     self.config(images_path=self.temp_dir, group='pxe')
     mgr_utils.mock_the_extension_manager(driver="fake_pxe")
     driver_info = INFO_DICT
     driver_info['pxe_deploy_key'] = 'fake-56789'
     n = db_utils.get_test_node(driver='fake_pxe', driver_info=driver_info)
     self.dbapi = dbapi.get_instance()
     self.node = self.dbapi.create_node(n)
     self.port = self.dbapi.create_port(
         db_utils.get_test_port(node_id=self.node.id))
Example #53
0
    def test_refresh(self):
        uuid = self.fake_port['uuid']
        self.mox.StubOutWithMock(self.dbapi, 'get_port')

        self.dbapi.get_port(uuid).AndReturn(self.fake_port)
        self.dbapi.get_port(uuid).AndReturn(
            utils.get_test_port(address="c3:54:00:cf:2d:40"))

        self.mox.ReplayAll()

        p = objects.Port.get_by_uuid(self.context, uuid)
        self.assertEqual(p.address, "52:54:00:cf:2d:31")

        p.refresh()

        self.assertEqual(p.address, "c3:54:00:cf:2d:40")
        self.mox.VerifyAll()
Example #54
0
    def test_ports_subresource(self):
        ndict = dbutils.get_test_node()
        self.dbapi.create_node(ndict)

        for id in range(2):
            pdict = dbutils.get_test_port(id=id, node_id=ndict['id'],
                                          uuid=utils.generate_uuid(),
                                          address='52:54:00:cf:2d:3%s' % id)
            self.dbapi.create_port(pdict)

        data = self.get_json('/nodes/%s/ports' % ndict['uuid'])
        self.assertEqual(2, len(data['ports']))
        self.assertNotIn('next', data.keys())

        # Test collection pagination
        data = self.get_json('/nodes/%s/ports?limit=1' % ndict['uuid'])
        self.assertEqual(1, len(data['ports']))
        self.assertIn('next', data.keys())
Example #55
0
 def setUp(self):
     super(PXEDriverTestCase, self).setUp()
     self.context = context.get_admin_context()
     self.context.auth_token = '4562138218392831'
     self.temp_dir = tempfile.mkdtemp()
     self.config(tftp_root=self.temp_dir, group='pxe')
     self.temp_dir = tempfile.mkdtemp()
     self.config(images_path=self.temp_dir, group='pxe')
     mgr_utils.mock_the_extension_manager(driver="fake_pxe")
     instance_info = INST_INFO_DICT
     instance_info['deploy_key'] = 'fake-56789'
     self.node = obj_utils.create_test_node(self.context,
                                            driver='fake_pxe',
                                            instance_info=instance_info,
                                            driver_info=DRV_INFO_DICT)
     self.dbapi = dbapi.get_instance()
     self.port = self.dbapi.create_port(db_utils.get_test_port(
                                                      node_id=self.node.id))
     self.config(group='conductor', api_url='http://127.0.0.1:1234/')
Example #56
0
    def test_ports_subresource(self):
        ndict = dbutils.get_test_node()
        self.dbapi.create_node(ndict)

        for id in xrange(2):
            pdict = dbutils.get_test_port(id=id,
                                          node_id=ndict['id'],
                                          uuid=uuidutils.generate_uuid())
            self.dbapi.create_port(pdict)

        data = self.get_json('/nodes/%s/ports' % ndict['uuid'])
        self.assertEqual(data['type'], 'port')
        self.assertEqual(len(data['items']), 2)
        self.assertEqual(len(data['links']), 0)

        # Test collection pagination
        data = self.get_json('/nodes/%s/ports?limit=1' % ndict['uuid'])
        self.assertEqual(data['type'], 'port')
        self.assertEqual(len(data['items']), 1)
        self.assertEqual(len(data['links']), 1)
Example #57
0
    def test_replace_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        pdict = dbutils.get_test_port(extra=extra,
                                      address="AA:BB:CC:DD:EE:FF",
                                      uuid=utils.generate_uuid())
        self.dbapi.create_port(pdict)

        new_value = 'new value'
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{
                                       'path': '/extra/foo2',
                                       'value': new_value,
                                       'op': 'replace'
                                   }])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
        result = self.get_json('/ports/%s' % pdict['uuid'])

        extra["foo2"] = new_value
        self.assertEqual(extra, result['extra'])
Example #58
0
    def test_save(self):
        uuid = self.fake_port['uuid']
        address = "b2:54:00:cf:2d:40"
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi, 'get_port_by_uuid',
                               autospec=True) as mock_get_port:
            mock_get_port.return_value = self.fake_port
            with mock.patch.object(self.dbapi, 'update_port',
                                   autospec=True) as mock_update_port:
                mock_update_port.return_value = (utils.get_test_port(
                    address=address, updated_at=test_time))
                p = objects.Port.get_by_uuid(self.context, uuid)
                p.address = address
                p.save()

                mock_get_port.assert_called_once_with(uuid)
                mock_update_port.assert_called_once_with(
                    uuid, {'address': "b2:54:00:cf:2d:40"})
                self.assertEqual(self.context, p._context)
                res_updated_at = (p.updated_at).replace(tzinfo=None)
                self.assertEqual(test_time, res_updated_at)
Example #59
0
    def test_replace_address_already_exist(self, mock_upd):
        address = 'aa:aa:aa:aa:aa:aa'
        dup = dbutils.get_test_port(address=address,
                                    uuid=utils.generate_uuid(),
                                    id=None)
        self.dbapi.create_port(dup)
        mock_upd.side_effect = exception.MACAlreadyExists(mac=address)
        response = self.patch_json('/ports/%s' % self.port.uuid,
                                   [{
                                       'path': '/address',
                                       'value': address,
                                       'op': 'replace'
                                   }],
                                   expect_errors=True)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(409, response.status_code)
        self.assertTrue(response.json['error_message'])
        self.assertTrue(mock_upd.called)

        kargs = mock_upd.call_args[0][1]
        self.assertEqual(address, kargs.address)
Example #60
0
    def setUp(self):
        super(TestPatch, self).setUp()
        ndict = dbutils.get_test_node()
        self.node = self.dbapi.create_node(ndict)
        self.pdict = dbutils.get_test_port(id=None)
        self.dbapi.create_port(self.pdict)

        def noop(*args, **kwargs):
            pass

        self.useFixture(
            fixtures.MonkeyPatch(
                'ironic.conductor.rpcapi.ConductorAPI.get_topic_for', noop))

        service = manager.ConductorManager('test-host', 'test-topic')

        def manager_update_port(*args, **kwargs):
            return service.update_port(*args[1:3])

        self.useFixture(
            fixtures.MonkeyPatch(
                'ironic.conductor.rpcapi.ConductorAPI.update_port',
                manager_update_port))