Browse Source

Merge "Add support of vnic_type to Profile"

changes/97/698797/9
Zuul 9 months ago
committed by Gerrit Code Review
parent
commit
32d6cf8b01
  1. 20
      senlin/profiles/os/nova/server.py
  2. 1
      senlin/tests/unit/profiles/test_nova_server.py
  3. 24
      senlin/tests/unit/profiles/test_nova_server_update.py
  4. 1
      senlin/tests/unit/profiles/test_nova_server_validate.py

20
senlin/profiles/os/nova/server.py

@ -64,10 +64,10 @@ class ServerProfile(base.Profile):
)
NETWORK_KEYS = (
PORT, FIXED_IP, NETWORK, PORT_SECURITY_GROUPS,
PORT, VNIC_TYPE, FIXED_IP, NETWORK, PORT_SECURITY_GROUPS,
FLOATING_NETWORK, FLOATING_IP,
) = (
'port', 'fixed_ip', 'network', 'security_groups',
'port', 'vnic_type', 'fixed_ip', 'network', 'security_groups',
'floating_network', 'floating_ip',
)
@ -182,6 +182,9 @@ class ServerProfile(base.Profile):
PORT: schema.String(
_('Port ID to be used by the network.'),
),
VNIC_TYPE: schema.String(
_('Define vnic_type to be used by port'),
),
FIXED_IP: schema.String(
_('Fixed IP to be used by the network.'),
),
@ -628,6 +631,15 @@ class ServerProfile(base.Profile):
) % {'p': self.PORT, 'fip': self.FIXED_IP})
result[self.FIXED_IP] = fixed_ip
# Validate vnic_type input
vnic_type = net_spec.get(self.VNIC_TYPE, None)
if vnic_type is not None:
if vnic_type not in ['normal', 'direct', 'macvtap']:
_verify(_("vnic_type: '%(v)s' is not supported."
"(supported types are: normal, direct, macvtap)"
) % {'v': vnic_type})
result[self.VNIC_TYPE] = vnic_type
# Check security_groups
error = self._check_security_groups(nc, net_spec, result)
_verify(error)
@ -661,8 +673,12 @@ class ServerProfile(base.Profile):
security_groups = net_spec.get(self.PORT_SECURITY_GROUPS, [])
if security_groups:
port_attr['security_groups'] = security_groups
vnic_type = net_spec.get(self.VNIC_TYPE, None)
if vnic_type:
port_attr['binding_vnic_type'] = vnic_type
try:
port = self.network(obj).port_create(**port_attr)
LOG.debug('Network port_attr : %s', port)
return port, None
except exc.InternalError as ex:
return None, ex

1
senlin/tests/unit/profiles/test_nova_server.py

@ -433,6 +433,7 @@ class TestNovaServerBasic(base.SenlinTestCase):
expect_params = {
'floating_network': None,
'network': 'FAKE_NET',
'vnic_type': None,
'fixed_ip': None,
'floating_ip': None,
'port': None,

24
senlin/tests/unit/profiles/test_nova_server_update.py

@ -1316,32 +1316,38 @@ class TestNovaServerUpdate(base.SenlinTestCase):
networks_create = [
{'floating_network': None, 'network': 'net1', 'fixed_ip': 'ip2',
'floating_ip': None, 'port': None, 'security_groups': None},
'floating_ip': None, 'port': None, 'vnic_type': None,
'security_groups': None},
{'floating_network': None, 'network': 'net2', 'fixed_ip': None,
'floating_ip': None, 'port': None, 'security_groups': None},
'floating_ip': None, 'port': None, 'vnic_type': None,
'security_groups': None},
{'floating_network': None, 'network': None, 'fixed_ip': None,
'floating_ip': None, 'port': 'port4', 'security_groups': None}
'floating_ip': None, 'port': 'port4', 'vnic_type': None,
'security_groups': None}
]
mock_create.assert_called_once_with(obj, networks_create)
networks_delete = [
{'floating_network': None, 'network': 'net1', 'fixed_ip': 'ip1',
'floating_ip': None, 'port': None, 'security_groups': None},
'floating_ip': None, 'port': None, 'vnic_type': None,
'security_groups': None},
{'floating_network': None, 'network': 'net1', 'fixed_ip': None,
'floating_ip': None, 'port': None, 'security_groups': None},
'floating_ip': None, 'port': None, 'vnic_type': None,
'security_groups': None},
{'floating_network': None, 'network': None, 'fixed_ip': None,
'floating_ip': None, 'port': 'port3', 'security_groups': None}
'floating_ip': None, 'port': 'port3', 'vnic_type': None,
'security_groups': None}
]
mock_delete.assert_called_once_with(obj, networks_delete)
networks_update = [
{'network': 'net3', 'port': None, 'fixed_ip': 'ip1',
'security_groups': ['default'], 'floating_network': None,
'floating_ip': None},
'vnic_type': None, 'floating_ip': None},
{'network': 'net4', 'port': None, 'fixed_ip': 'ip1',
'security_groups': ['default'], 'floating_network': None,
'floating_ip': None},
'vnic_type': None, 'floating_ip': None},
{'network': None, 'port': 'port5', 'fixed_ip': None,
'security_groups': ['default', 'blah'], 'floating_network': None,
'floating_ip': None}
'vnic_type': None, 'floating_ip': None}
]
mock_update.assert_called_once_with(obj, networks_update)

1
senlin/tests/unit/profiles/test_nova_server_validate.py

@ -38,6 +38,7 @@ spec = {
'floating_network': 'FAKE_FLOATING_NET',
'security_groups': ['FAKE_SECURITY_GROUP'],
'port': 'FAKE_PORT',
'vnic_type': 'direct',
'fixed_ip': 'FAKE_IP',
'network': 'FAKE_NET',
}],

Loading…
Cancel
Save