summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit
diff options
context:
space:
mode:
authorHa Van Tu <tuhv@vn.fujitsu.com>2017-01-12 09:57:53 +0700
committerDean Troyer <dtroyer@gmail.com>2017-04-05 15:56:52 +0000
commit5ff2cfd042de7afc4323a3b306ff5be1882fba46 (patch)
tree9cb5fc568157e31c5ec01490ca56da89c0e51192 /openstackclient/tests/unit
parent65b61d3a9c08a43cc0746ac17fec00682a720913 (diff)
downloadpython-openstackclient-5ff2cfd042de7afc4323a3b306ff5be1882fba46.tar.gz
Add "qos-policy" option to "port create" & "port set"
This patch adds "qos-policy" option to "port create" command, and "qos-policy", "no-qos-policy" options to "port set" command and "qos-policy" option to "port unset". Change-Id: I78072e1ff0dd30a2e23a0fb833ce6ab5cf246016 Co-Authored-By: Nguyen Phuong An <AnNP@vn.fujitsu.com> Co-Authored-By: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> Partial-Bug: #1612136 Partially-Implements: blueprint network-commands-options
Diffstat (limited to 'openstackclient/tests/unit')
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py60
2 files changed, 61 insertions, 1 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index d3685409..9a289941 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -572,6 +572,7 @@ class FakePort(object):
'security_group_ids': [],
'status': 'ACTIVE',
'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
@@ -590,6 +591,7 @@ class FakePort(object):
port.is_port_security_enabled = port_attrs['port_security_enabled']
port.project_id = port_attrs['tenant_id']
port.security_group_ids = port_attrs['security_group_ids']
+ port.qos_policy_id = port_attrs['qos_policy_id']
return port
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index 701af879..851bf25a 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -57,6 +57,7 @@ class TestPort(network_fakes.TestNetworkV2):
'network_id',
'port_security_enabled',
'project_id',
+ 'qos_policy_id',
'security_group_ids',
'status',
)
@@ -82,6 +83,7 @@ class TestPort(network_fakes.TestNetworkV2):
fake_port.network_id,
fake_port.port_security_enabled,
fake_port.project_id,
+ fake_port.qos_policy_id,
utils.format_list(fake_port.security_group_ids),
fake_port.status,
)
@@ -422,6 +424,35 @@ class TestCreatePort(TestPort):
self.assertEqual(ref_columns, columns)
self.assertEqual(ref_data, data)
+ def test_create_port_with_qos(self):
+ qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
+ self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
+ arglist = [
+ '--network', self._port.network_id,
+ '--qos-policy', qos_policy.id,
+ 'test-port',
+ ]
+ verifylist = [
+ ('network', self._port.network_id,),
+ ('enable', True),
+ ('qos_policy', qos_policy.id),
+ ('name', 'test-port'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_port.assert_called_once_with(**{
+ 'admin_state_up': True,
+ 'network_id': self._port.network_id,
+ 'qos_policy_id': qos_policy.id,
+ 'name': 'test-port',
+ })
+
+ ref_columns, ref_data = self._get_common_cols_data(self._port)
+ self.assertEqual(ref_columns, columns)
+ self.assertEqual(ref_data, data)
+
def test_create_port_security_enabled(self):
arglist = [
'--network', self._port.network_id,
@@ -1316,6 +1347,30 @@ class TestSetPort(TestPort):
'port_security_enabled': False,
})
+ def test_set_port_with_qos(self):
+ qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
+ self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
+ _testport = network_fakes.FakePort.create_one_port(
+ {'qos_policy_id': None})
+ self.network.find_port = mock.Mock(return_value=_testport)
+ arglist = [
+ '--qos-policy', qos_policy.id,
+ _testport.name,
+ ]
+ verifylist = [
+ ('qos_policy', qos_policy.id),
+ ('port', _testport.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'qos_policy_id': qos_policy.id,
+ }
+ self.network.update_port.assert_called_once_with(_testport, **attrs)
+ self.assertIsNone(result)
+
class TestShowPort(TestPort):
@@ -1379,6 +1434,7 @@ class TestUnsetPort(TestPort):
'--fixed-ip',
'subnet=042eb10a-3a18-4658-ab-cf47c8d03152,ip-address=1.0.0.0',
'--binding-profile', 'Superman',
+ '--qos-policy',
self._testport.name,
]
verifylist = [
@@ -1386,6 +1442,7 @@ class TestUnsetPort(TestPort):
'subnet': '042eb10a-3a18-4658-ab-cf47c8d03152',
'ip-address': '1.0.0.0'}]),
('binding_profile', ['Superman']),
+ ('qos_policy', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -1395,7 +1452,8 @@ class TestUnsetPort(TestPort):
'fixed_ips': [{
'subnet_id': '042eb10a-3a18-4658-ab-cf47c8d03152',
'ip_address': '0.0.0.1'}],
- 'binding:profile': {'batman': 'Joker'}
+ 'binding:profile': {'batman': 'Joker'},
+ 'qos_policy_id': None
}
self.network.update_port.assert_called_once_with(
self._testport, **attrs)