示例#1
0
文件: utils.py 项目: pshchelo/ironic
def port_post_data(**kw):
    port = db_utils.get_test_port(**kw)
    # These values are not part of the API object
    port.pop('version')
    port.pop('node_id')
    port.pop('portgroup_id')
    internal = port_controller.PortPatchType.internal_attrs()
    return remove_internal(port, internal)
示例#2
0
def port_post_data(**kw):
    port = utils.get_test_port(**kw)
    # node_id is not part of the API object
    port.pop('node_id')
    # portgroup_id is not part of the API object
    port.pop('portgroup_id')
    internal = port_controller.PortPatchType.internal_attrs()
    return remove_internal(port, internal)
示例#3
0
文件: utils.py 项目: Tehsmash/ironic
def port_post_data(**kw):
    port = db_utils.get_test_port(**kw)
    # These values are not part of the API object
    port.pop('version')
    port.pop('node_id')
    port.pop('portgroup_id')
    # NOTE(mgoddard): Physical network is not yet supported by the REST API.
    port.pop('physical_network')
    internal = port_controller.PortPatchType.internal_attrs()
    return remove_internal(port, internal)
示例#4
0
    def test_create(self):
        port = objects.Port(self.context, **self.fake_port)
        with mock.patch.object(self.dbapi, 'create_port',
                               autospec=True) as mock_create_port:
            mock_create_port.return_value = db_utils.get_test_port()

            port.create()

            args, _kwargs = mock_create_port.call_args
            self.assertEqual(objects.Port.VERSION, args[0]['version'])
示例#5
0
文件: utils.py 项目: kimcharli/ironic
def port_post_data(**kw):
    port = utils.get_test_port(**kw)
    # node_id is not part of the API object
    port.pop('node_id')
    # TODO(vsaienko): remove when API part is added
    port.pop('local_link_connection')
    port.pop('pxe_enabled')
    # portgroup_id is not part of the API object
    port.pop('portgroup_id')
    internal = port_controller.PortPatchType.internal_attrs()
    return remove_internal(port, internal)
示例#6
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)
            self.assertEqual(self.context, p._context)
示例#7
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
示例#8
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)
示例#9
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)
            self.assertEqual(self.context, p._context)
示例#10
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)
示例#11
0
 def test_create_port(self):
     fake_port = db_utils.get_test_port()
     self._test_rpcapi('create_port',
                       'call',
                       version='1.41',
                       port_obj=fake_port)
示例#12
0
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.vif_id = 'some_uuid'
     extra = {'vif_port_id': self.vif_id}
     self.fake_port = db_utils.get_test_port(extra=extra)
示例#13
0
def port_post_data(**kw):
    port = utils.get_test_port(**kw)
    # node_id is not part of the API object
    port.pop('node_id')
    internal = port_controller.PortPatchType.internal_attrs()
    return remove_internal(port, internal)
示例#14
0
 def test_update_port(self):
     fake_port = dbutils.get_test_port()
     self._test_rpcapi("update_port", "call", version="1.13", port_obj=fake_port)
示例#15
0
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.fake_port = db_utils.get_test_port()
示例#16
0
 def setUp(self):
     super(TestPortObject, self).setUp()
     self.fake_port = db_utils.get_test_port(name='port-name')
示例#17
0
 def test_update_port(self):
     fake_port = dbutils.get_test_port()
     self._test_rpcapi('update_port',
                       'call',
                       version='1.13',
                       port_obj=fake_port)
示例#18
0
 def test_create_port(self):
     fake_port = db_utils.get_test_port()
     self._test_rpcapi('create_port',
                       'call',
                       version='1.41',
                       port_obj=fake_port)
示例#19
0
 def setUp(self):
     super(TestPortObject, self).setUp()
     self.fake_port = utils.get_test_port()
示例#20
0
 def setUp(self):
     super(TestPortObject, self).setUp()
     self.fake_port = utils.get_test_port()
示例#21
0
def port_post_data(**kw):
    port = db_utils.get_test_port(**kw)
    return remove_other_fields(port, port_controller.PORT_SCHEMA['properties'])
示例#22
0
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.vif_id = 'some_uuid'
     extra = {'vif_port_id': self.vif_id}
     self.fake_port = db_utils.get_test_port(extra=extra)