Merge "[PTP dual NIC config] Adding name to ptp_interface"

This commit is contained in:
Zuul 2021-12-22 18:57:27 +00:00 committed by Gerrit Code Review
commit db2edd395a
10 changed files with 28 additions and 23 deletions

View File

@ -57,6 +57,9 @@ class PtpInterface(base.APIBase):
# Fields of PtpInterface
name = wtypes.text
"Name given to the PTP interface"
ptp_instance_id = int
"ID for the PTP instance this interface is associated with"
@ -86,6 +89,7 @@ class PtpInterface(base.APIBase):
ptp_interface.unset_fields_except(['uuid',
'type',
'capabilities',
'name',
'ptp_instance_id',
'ptp_instance_uuid',
'ptp_instance_name',
@ -170,6 +174,10 @@ class PtpInterfaceController(rest.RestController):
# Create a new PTP interface
ptp_interface_dict = ptp_interface.as_dict()
"""
TODO: enforce "name" as required field here
"""
instance_uuid = ptp_interface_dict.pop('ptp_instance_uuid', None)
instance = objects.ptp_instance.get_by_uuid(pecan.request.context,
instance_uuid)

View File

@ -461,8 +461,7 @@ class PtpInterfaceAlreadyExists(Conflict):
class PtpParameterAlreadyExists(Conflict):
message = _("A PTP parameter with name '%(name)s' and value "
"'%(value)s' already exists.")
message = _("A PTP parameter with UUID %(uuid)s already exists.")
class PtpParameterOwnershipAlreadyExists(Conflict):

View File

@ -4035,8 +4035,7 @@ class Connection(api.Connection):
session.add(ptp_parameter)
session.flush()
except db_exc.DBDuplicateEntry:
raise exception.PtpParameterAlreadyExists(
name=values['name'], value=values['value'])
raise exception.PtpParameterAlreadyExists(uuid=values['uuid'])
return self._ptp_parameter_get(values['uuid'])
@objects.objectify(objects.ptp_parameter)

View File

@ -60,8 +60,6 @@ def upgrade(migrate_engine):
Column('name', String(255), nullable=False),
Column('value', String(255)),
UniqueConstraint('name', 'value', name='u_paramnamevalue'),
mysql_engine=ENGINE,
mysql_charset=CHARSET,
)
@ -102,6 +100,8 @@ def upgrade(migrate_engine):
Column('name', String(255), unique=True, nullable=False),
Column('service', String(255)),
Column('extra_info', Text),
mysql_engine=ENGINE,
mysql_charset=CHARSET,
)
@ -118,11 +118,14 @@ def upgrade(migrate_engine):
Column('id', Integer,
ForeignKey('ptp_parameter_owners.id', ondelete="CASCADE"),
primary_key=True, nullable=False),
Column('name', String(255), unique=True),
Column('ptp_instance_id', Integer,
ForeignKey('ptp_instances.id', ondelete="CASCADE"),
nullable=False),
Column('extra_info', Text),
mysql_engine=ENGINE,
mysql_charset=CHARSET,
)

View File

@ -818,8 +818,6 @@ class PtpParameters(Base):
"foreign(PtpParameterOwnerships.owner_uuid)",
back_populates="ptp_parameters", lazy="joined", join_depth=1)
UniqueConstraint('name', 'value', name='u_paramnamevalue')
class PtpParameterOwners(Base):
__tablename__ = "ptp_parameter_owners"
@ -875,6 +873,7 @@ class PtpInterfaces(PtpParameterOwners):
id = Column(Integer, ForeignKey('ptp_parameter_owners.id'),
primary_key=True,
nullable=False)
name = Column(String(255), unique=True)
ptp_instance_id = Column(Integer,
ForeignKey('ptp_instances.id',
ondelete='CASCADE'),

View File

@ -35,6 +35,7 @@ class PtpInterface(ptp_paramowner.PtpParameterOwner):
dbapi = db_api.get_instance()
fields = dict({
'name': utils.str_or_none,
'ptp_instance_id': utils.int_or_none,
'ptp_instance_uuid': utils.str_or_none,
'ptp_instance_name': utils.str_or_none,

View File

@ -53,9 +53,9 @@ class BasePtpInterfaceTestCase(base.FunctionalTest, dbbase.BaseHostTestCase):
self.API_PREFIX,
interface_uuid)
def get_post_object(self, ptp_instance_uuid):
def get_post_object(self, ptp_instance_uuid, name=None):
ptp_interface_db = dbutils.get_test_ptp_interface(
ptp_instance_uuid=ptp_instance_uuid)
ptp_instance_uuid=ptp_instance_uuid, name=name)
return ptp_interface_db
@ -64,8 +64,8 @@ class TestCreatePtpInterface(BasePtpInterfaceTestCase):
def setUp(self):
super(TestCreatePtpInterface, self).setUp()
def _create_ptp_interface_success(self, ptp_instance_uuid):
ptp_interface_db = self.get_post_object(ptp_instance_uuid)
def _create_ptp_interface_success(self, name, ptp_instance_uuid):
ptp_interface_db = self.get_post_object(ptp_instance_uuid, name)
response = self.post_json(self.API_PREFIX, ptp_interface_db,
headers=self.API_HEADERS)
self.assertEqual('application/json', response.content_type)
@ -76,9 +76,9 @@ class TestCreatePtpInterface(BasePtpInterfaceTestCase):
ptp_interface_db[self.COMMON_FIELD])
"""
def _create_ptp_interface_failed(self, ptp_instance_uuid,
def _create_ptp_interface_failed(self, name, ptp_instance_uuid,
status_code, error_message):
ptp_interface_db = self.get_post_object(ptp_instance_uuid)
ptp_interface_db = self.get_post_object(ptp_instance_uuid, name)
response = self.post_json(self.API_PREFIX, ptp_interface_db,
headers=self.API_HEADERS,
expect_errors=True)
@ -87,10 +87,11 @@ class TestCreatePtpInterface(BasePtpInterfaceTestCase):
self.assertIn(error_message, response.json['error_message'])
def test_create_ptp_interface_ok(self):
self._create_ptp_interface_success(self.instance.uuid)
self._create_ptp_interface_success('test', self.instance.uuid)
def test_create_ptp_interface_invalid_instance(self):
self._create_ptp_interface_failed(
'test',
'32dbb999-6c10-448d-aeca-964c50af6384',
status_code=http_client.NOT_FOUND,
error_message='No PTP instance with id 32dbb999-6c10-448d-aeca-964c50af6384 found.')

View File

@ -112,13 +112,6 @@ class TestCreatePtpParameter(BasePtpParameterTestCase):
self._create_ptp_parameter_success(
name=self.name, value='another-value')
def test_create_ptp_parameter_duplicate_failed(self):
self._create_ptp_parameter_failed(
name=self.name,
value=self.value,
status_code=http_client.CONFLICT,
error_message='already exists')
class TestSetPtpParameter(BasePtpParameterTestCase):
name = 'test-param'

View File

@ -2039,6 +2039,7 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
'updated_at': 'DateTime',
'deleted_at': 'DateTime',
'id': 'Integer',
'name': 'String',
'ptp_instance_id': 'Integer'
}
for column, column_type in ptp_interface_columns.items():

View File

@ -557,7 +557,8 @@ def create_test_ptp_instance(**kw):
def get_test_ptp_interface(**kw):
ptp_interface = {
'ptp_instance_id': kw.get('ptp_instance_id'),
'ptp_instance_uuid': kw.get('ptp_instance_uuid', None)
'ptp_instance_uuid': kw.get('ptp_instance_uuid', None),
'name': kw.get('name', None)
}
return ptp_interface