summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/network
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2017-04-29 00:32:32 +0000
committerAkihiro Motoki <amotoki@gmail.com>2017-07-23 21:54:32 +0000
commit57e5840710c3b2b74d31bfd6a0da739e0fc747ed (patch)
tree93fbb66cdc78f93062c4be7bddd8c8d8e45ff365 /openstackclient/tests/functional/network
parente889ba1524c7e48a86ef41361a17cdb93b9942c2 (diff)
downloadpython-openstackclient-57e5840710c3b2b74d31bfd6a0da739e0fc747ed.tar.gz
Network tag support
Neutron tag mechanism now supports network, subnet, port, subnetpool and router. Tag support for more resources is planned. This commit introduces a common mixin class to implement tag operation and individual resource consumes it. To support tag remove, network unset command is added. Implements blueprint neutron-client-tag Change-Id: Iad59d052f46896d27d73c22d6d4bb3df889f2352
Diffstat (limited to 'openstackclient/tests/functional/network')
-rw-r--r--openstackclient/tests/functional/network/v2/common.py81
-rw-r--r--openstackclient/tests/functional/network/v2/test_network.py4
-rw-r--r--openstackclient/tests/functional/network/v2/test_port.py13
-rw-r--r--openstackclient/tests/functional/network/v2/test_router.py4
-rw-r--r--openstackclient/tests/functional/network/v2/test_subnet.py10
-rw-r--r--openstackclient/tests/functional/network/v2/test_subnet_pool.py8
6 files changed, 115 insertions, 5 deletions
diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py
index e3835abf..a18bc48f 100644
--- a/openstackclient/tests/functional/network/v2/common.py
+++ b/openstackclient/tests/functional/network/v2/common.py
@@ -10,6 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
+import json
+import uuid
+
from openstackclient.tests.functional import base
@@ -20,3 +23,81 @@ class NetworkTests(base.TestCase):
def setUpClass(cls):
super(NetworkTests, cls).setUpClass()
cls.haz_network = base.is_service_enabled('network')
+
+
+class NetworkTagTests(NetworkTests):
+ """Functional tests with tag operation"""
+
+ base_command = None
+
+ def test_tag_operation(self):
+ # Get project IDs
+ cmd_output = json.loads(self.openstack('token issue -f json '))
+ auth_project_id = cmd_output['project_id']
+
+ # Network create with no options
+ name1 = self._create_resource_and_tag_check('', [])
+ # Network create with tags
+ name2 = self._create_resource_and_tag_check('--tag red --tag blue',
+ ['red', 'blue'])
+ # Network create with no tag explicitly
+ name3 = self._create_resource_and_tag_check('--no-tag', [])
+
+ self._set_resource_and_tag_check('set', name1, '--tag red --tag green',
+ ['red', 'green'])
+
+ list_expected = ((name1, ['red', 'green']),
+ (name2, ['red', 'blue']),
+ (name3, []))
+ self._list_tag_check(auth_project_id, list_expected)
+
+ self._set_resource_and_tag_check('set', name1, '--tag blue',
+ ['red', 'green', 'blue'])
+ self._set_resource_and_tag_check(
+ 'set', name1,
+ '--no-tag --tag yellow --tag orange --tag purple',
+ ['yellow', 'orange', 'purple'])
+ self._set_resource_and_tag_check('unset', name1, '--tag yellow',
+ ['orange', 'purple'])
+ self._set_resource_and_tag_check('unset', name1, '--all-tag', [])
+ self._set_resource_and_tag_check('set', name2, '--no-tag', [])
+
+ def _assertTagsEqual(self, expected, actual):
+ # TODO(amotoki): Should migrate to cliff format columns.
+ # At now, unit test assert method needs to be replaced
+ # to handle format columns, so format_list() is used.
+ # NOTE: The order of tag is undeterminestic.
+ actual_tags = filter(bool, actual.split(', '))
+ self.assertEqual(set(expected), set(actual_tags))
+
+ def _list_tag_check(self, project_id, expected):
+ cmd_output = json.loads(self.openstack(
+ '{} list --long --project {} -f json'.format(self.base_command,
+ project_id)))
+ for name, tags in expected:
+ net = [n for n in cmd_output if n['Name'] == name][0]
+ self._assertTagsEqual(tags, net['Tags'])
+
+ def _create_resource_for_tag_test(self, name, args):
+ return json.loads(self.openstack(
+ '{} create -f json {} {}'.format(self.base_command, args, name)
+ ))
+
+ def _create_resource_and_tag_check(self, args, expected):
+ name = uuid.uuid4().hex
+ cmd_output = self._create_resource_for_tag_test(name, args)
+ self.addCleanup(
+ self.openstack, '{} delete {}'.format(self.base_command, name))
+ self.assertIsNotNone(cmd_output["id"])
+ self._assertTagsEqual(expected, cmd_output['tags'])
+ return name
+
+ def _set_resource_and_tag_check(self, command, name, args, expected):
+ cmd_output = self.openstack(
+ '{} {} {} {}'.format(self.base_command, command, args, name)
+ )
+ self.assertFalse(cmd_output)
+ cmd_output = json.loads(self.openstack(
+ '{} show -f json {}'.format(self.base_command, name)
+ ))
+ self._assertTagsEqual(expected, cmd_output['tags'])
diff --git a/openstackclient/tests/functional/network/v2/test_network.py b/openstackclient/tests/functional/network/v2/test_network.py
index 91939703..40fb382a 100644
--- a/openstackclient/tests/functional/network/v2/test_network.py
+++ b/openstackclient/tests/functional/network/v2/test_network.py
@@ -16,9 +16,11 @@ import uuid
from openstackclient.tests.functional.network.v2 import common
-class NetworkTests(common.NetworkTests):
+class NetworkTests(common.NetworkTagTests):
"""Functional tests for network"""
+ base_command = 'network'
+
def setUp(self):
super(NetworkTests, self).setUp()
# Nothing in this class works with Nova Network
diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py
index 09ac3566..a7059790 100644
--- a/openstackclient/tests/functional/network/v2/test_port.py
+++ b/openstackclient/tests/functional/network/v2/test_port.py
@@ -16,9 +16,14 @@ import uuid
from openstackclient.tests.functional.network.v2 import common
-class PortTests(common.NetworkTests):
+class PortTests(common.NetworkTagTests):
"""Functional tests for port"""
+ base_command = 'port'
+
+ NAME = uuid.uuid4().hex
+ NETWORK_NAME = uuid.uuid4().hex
+
@classmethod
def setUpClass(cls):
common.NetworkTests.setUpClass()
@@ -250,3 +255,9 @@ class PortTests(common.NetworkTests):
sg_id2,
json_output.get('security_group_ids'),
)
+
+ def _create_resource_for_tag_test(self, name, args):
+ return json.loads(self.openstack(
+ '{} create -f json --network {} {} {}'
+ .format(self.base_command, self.NETWORK_NAME, args, name)
+ ))
diff --git a/openstackclient/tests/functional/network/v2/test_router.py b/openstackclient/tests/functional/network/v2/test_router.py
index 2e5cb5ef..95c5a96f 100644
--- a/openstackclient/tests/functional/network/v2/test_router.py
+++ b/openstackclient/tests/functional/network/v2/test_router.py
@@ -16,9 +16,11 @@ import uuid
from openstackclient.tests.functional.network.v2 import common
-class RouterTests(common.NetworkTests):
+class RouterTests(common.NetworkTagTests):
"""Functional tests for router"""
+ base_command = 'router'
+
def setUp(self):
super(RouterTests, self).setUp()
# Nothing in this class works with Nova Network
diff --git a/openstackclient/tests/functional/network/v2/test_subnet.py b/openstackclient/tests/functional/network/v2/test_subnet.py
index 040b645b..d5309ee6 100644
--- a/openstackclient/tests/functional/network/v2/test_subnet.py
+++ b/openstackclient/tests/functional/network/v2/test_subnet.py
@@ -17,9 +17,11 @@ import uuid
from openstackclient.tests.functional.network.v2 import common
-class SubnetTests(common.NetworkTests):
+class SubnetTests(common.NetworkTagTests):
"""Functional tests for subnet"""
+ base_command = 'subnet'
+
@classmethod
def setUpClass(cls):
common.NetworkTests.setUpClass()
@@ -285,3 +287,9 @@ class SubnetTests(common.NetworkTests):
# break and no longer retry if create successfully
break
return cmd_output
+
+ def _create_resource_for_tag_test(self, name, args):
+ cmd = ('subnet create -f json --network ' +
+ self.NETWORK_NAME + ' ' + args +
+ ' --subnet-range')
+ return self._subnet_create(cmd, name)
diff --git a/openstackclient/tests/functional/network/v2/test_subnet_pool.py b/openstackclient/tests/functional/network/v2/test_subnet_pool.py
index a4b823f1..46aa6f14 100644
--- a/openstackclient/tests/functional/network/v2/test_subnet_pool.py
+++ b/openstackclient/tests/functional/network/v2/test_subnet_pool.py
@@ -17,9 +17,11 @@ import uuid
from openstackclient.tests.functional.network.v2 import common
-class SubnetPoolTests(common.NetworkTests):
+class SubnetPoolTests(common.NetworkTagTests):
"""Functional tests for subnet pool"""
+ base_command = 'subnet pool'
+
def setUp(self):
super(SubnetPoolTests, self).setUp()
# Nothing in this class works with Nova Network
@@ -321,3 +323,7 @@ class SubnetPoolTests(common.NetworkTests):
break
return cmd_output, pool_prefix
+
+ def _create_resource_for_tag_test(self, name, args):
+ cmd_output, _pool_prefix = self._subnet_pool_create(args, name)
+ return cmd_output