summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 12:40:06 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 12:40:06 +0000
commitb720323d6193cb600c85df2cae3c6186a3c9674c (patch)
treebe471639c2fb2c719357364b560908a41428286c
parentdb9ef89ee0e62030eff5ef5a234a4112654194f3 (diff)
parentaa9e1980211cda32b234cc7a86d739175ada4ca8 (diff)
Merge "Use versionedobjects PCIAddress field"
-rw-r--r--os_vif/objects/fields.py20
-rw-r--r--os_vif/objects/vif.py4
-rwxr-xr-xos_vif/tests/test_fields.py36
3 files changed, 2 insertions, 58 deletions
diff --git a/os_vif/objects/fields.py b/os_vif/objects/fields.py
index 004510c..b0084e4 100644
--- a/os_vif/objects/fields.py
+++ b/os_vif/objects/fields.py
@@ -12,27 +12,7 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15import re
16
17from oslo_versionedobjects import fields 15from oslo_versionedobjects import fields
18import six
19
20
21class PCIAddress(fields.FieldType):
22
23 _REGEX = re.compile(r'^[0-9a-f]{4}:[0-9a-f]{2}:[0-1][0-9a-f].[0-7]$')
24
25 @staticmethod
26 def coerce(obj, attr, value):
27 if isinstance(value, six.string_types):
28 newvalue = value.lower()
29 if PCIAddress._REGEX.match(newvalue):
30 return newvalue
31 raise ValueError("Malformed PCI address %s", value)
32
33
34class PCIAddressField(fields.AutoTypedField):
35 AUTO_TYPE = PCIAddress()
36 16
37 17
38class VIFDirectMode(fields.Enum): 18class VIFDirectMode(fields.Enum):
diff --git a/os_vif/objects/vif.py b/os_vif/objects/vif.py
index f0af973..1c2cee0 100644
--- a/os_vif/objects/vif.py
+++ b/os_vif/objects/vif.py
@@ -107,7 +107,7 @@ class VIFDirect(VIFBase):
107 'vif_name': fields.StringField(), 107 'vif_name': fields.StringField(),
108 108
109 # The PCI address of the host device 109 # The PCI address of the host device
110 'dev_address': osv_fields.PCIAddressField(), 110 'dev_address': fields.PCIAddressField(),
111 111
112 # Port connection mode 112 # Port connection mode
113 'mode': osv_fields.VIFDirectModeField(), 113 'mode': osv_fields.VIFDirectModeField(),
@@ -157,7 +157,7 @@ class VIFHostDevice(VIFBase):
157 'dev_type': osv_fields.VIFHostDeviceDevTypeField(), 157 'dev_type': osv_fields.VIFHostDeviceDevTypeField(),
158 158
159 # The PCI address of the host device 159 # The PCI address of the host device
160 'dev_address': osv_fields.PCIAddressField(), 160 'dev_address': fields.PCIAddressField(),
161 } 161 }
162 162
163 163
diff --git a/os_vif/tests/test_fields.py b/os_vif/tests/test_fields.py
deleted file mode 100755
index 3746508..0000000
--- a/os_vif/tests/test_fields.py
+++ /dev/null
@@ -1,36 +0,0 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from oslo_versionedobjects.tests import test_fields
14
15from os_vif.objects import fields
16
17
18class TestPCIAddress(test_fields.TestField):
19 def setUp(self):
20 super(TestPCIAddress, self).setUp()
21 self.field = fields.PCIAddressField()
22 self.coerce_good_values = [
23 ('0000:02:00.0', '0000:02:00.0'),
24 ('FFFF:FF:1F.7', 'ffff:ff:1f.7'),
25 ('fFfF:fF:1F.7', 'ffff:ff:1f.7'),
26 ]
27 self.coerce_bad_values = [
28 '000:02:00.0', # Too short
29 '00000:02:00.0', # Too long
30 'FFFF:FF:2F.7', # Bad slot
31 'FFFF:GF:1F.7', # Bad octal
32 1123123, # Number
33 {}, # dict
34 ]
35 self.to_primitive_values = self.coerce_good_values[0:1]
36 self.from_primitive_values = self.coerce_good_values[0:1]