summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_flavor.py163
-rw-r--r--openstackclient/tests/functional/network/v2/test_subnet.py268
-rw-r--r--openstackclient/tests/functional/volume/v1/test_volume.py9
-rw-r--r--openstackclient/tests/functional/volume/v2/test_volume.py22
-rw-r--r--openstackclient/tests/functional/volume/v3/__init__.py0
-rw-r--r--openstackclient/tests/functional/volume/v3/common.py23
-rw-r--r--openstackclient/tests/functional/volume/v3/test_qos.py23
-rw-r--r--openstackclient/tests/functional/volume/v3/test_snapshot.py23
-rw-r--r--openstackclient/tests/functional/volume/v3/test_transfer_request.py24
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume.py23
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume_type.py23
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py25
-rw-r--r--openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py267
-rw-r--r--openstackclient/tests/unit/volume/v1/test_volume.py6
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py18
-rw-r--r--openstackclient/tests/unit/volume/v3/__init__.py0
16 files changed, 801 insertions, 116 deletions
diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor.py b/openstackclient/tests/functional/network/v2/test_network_flavor.py
index e37a7bc7..b2fc2eae 100644
--- a/openstackclient/tests/functional/network/v2/test_network_flavor.py
+++ b/openstackclient/tests/functional/network/v2/test_network_flavor.py
@@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-import re
+
+import json
import uuid
from openstackclient.tests.functional import base
@@ -19,135 +20,157 @@ from openstackclient.tests.functional import base
class NetworkFlavorTests(base.TestCase):
"""Functional tests for network flavor."""
- @classmethod
- def setUpClass(cls):
- # Set up some regex for matching below
- cls.re_name = re.compile("name\s+\|\s+([^|]+?)\s+\|")
- cls.re_enabled = re.compile("enabled\s+\|\s+(\S+)")
- cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
- cls.SERVICE_TYPE = 'L3_ROUTER_NAT'
-
def test_network_flavor_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- raw_output = self.openstack(
- 'network flavor create --description testdescription --enable'
- ' --service-type ' + self.SERVICE_TYPE + ' ' + name1,
- )
+ cmd_output = json.loads(self.openstack(
+ 'network flavor create -f json --description testdescription '
+ '--enable --service-type L3_ROUTER_NAT ' + name1,
+ ))
self.assertEqual(
name1,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'True',
- re.search(self.re_enabled, raw_output).group(1))
+ True,
+ cmd_output['enabled'],
+ )
self.assertEqual(
'testdescription',
- re.search(self.re_description, raw_output).group(1))
+ cmd_output['description'],
+ )
name2 = uuid.uuid4().hex
- raw_output = self.openstack(
- 'network flavor create --description testdescription1 --disable'
- ' --service-type ' + self.SERVICE_TYPE + ' ' + name2,
- )
+ cmd_output = json.loads(self.openstack(
+ 'network flavor create -f json --description testdescription1 '
+ '--disable --service-type L3_ROUTER_NAT ' + name2,
+ ))
self.assertEqual(
name2,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'False',
- re.search(self.re_enabled, raw_output).group(1))
+ False,
+ cmd_output['enabled'],
+ )
self.assertEqual(
'testdescription1',
- re.search(self.re_description, raw_output).group(1))
-
+ cmd_output['description'],
+ )
raw_output = self.openstack(
'network flavor delete ' + name1 + " " + name2)
self.assertOutput('', raw_output)
def test_network_flavor_list(self):
+ """Test create defaults, list filters, delete"""
name1 = uuid.uuid4().hex
- raw_output = self.openstack(
- 'network flavor create --description testdescription --enable'
- ' --service-type ' + self.SERVICE_TYPE + ' ' + name1,
- )
+ cmd_output = json.loads(self.openstack(
+ 'network flavor create -f json --description testdescription '
+ '--enable --service-type L3_ROUTER_NAT ' + name1,
+ ))
self.addCleanup(self.openstack, "network flavor delete " + name1)
self.assertEqual(
name1,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'True',
- re.search(self.re_enabled, raw_output).group(1))
+ True,
+ cmd_output['enabled'],
+ )
self.assertEqual(
'testdescription',
- re.search(self.re_description, raw_output).group(1))
+ cmd_output['description'],
+ )
name2 = uuid.uuid4().hex
- raw_output = self.openstack(
- 'network flavor create --description testdescription --disable'
- ' --service-type ' + self.SERVICE_TYPE + ' ' + name2,
- )
+ cmd_output = json.loads(self.openstack(
+ 'network flavor create -f json --description testdescription1 '
+ '--disable --service-type L3_ROUTER_NAT ' + name2,
+ ))
self.assertEqual(
name2,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'False',
- re.search(self.re_enabled, raw_output).group(1))
+ False,
+ cmd_output['enabled'],
+ )
self.assertEqual(
- 'testdescription',
- re.search(self.re_description, raw_output).group(1))
+ 'testdescription1',
+ cmd_output['description'],
+ )
self.addCleanup(self.openstack, "network flavor delete " + name2)
# Test list
- raw_output = self.openstack('network flavor list')
- self.assertIsNotNone(raw_output)
- self.assertIsNotNone(re.search(name1, raw_output))
- self.assertIsNotNone(re.search(name2, raw_output))
+ cmd_output = json.loads(self.openstack(
+ 'network flavor list -f json ',))
+ self.assertIsNotNone(cmd_output)
+
+ name_list = [item.get('Name') for item in cmd_output]
+ self.assertIn(name1, name_list)
+ self.assertIn(name2, name_list)
def test_network_flavor_set(self):
+ """Tests create options, set, show, delete"""
name = uuid.uuid4().hex
newname = name + "_"
- raw_output = self.openstack(
- 'network flavor create --description testdescription --enable'
- ' --service-type ' + self.SERVICE_TYPE + ' ' + name,
- )
+ cmd_output = json.loads(self.openstack(
+ 'network flavor create -f json --description testdescription '
+ '--disable --service-type L3_ROUTER_NAT ' + name,
+ ))
self.addCleanup(self.openstack, "network flavor delete " + newname)
self.assertEqual(
name,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'True',
- re.search(self.re_enabled, raw_output).group(1))
+ False,
+ cmd_output['enabled'],
+ )
self.assertEqual(
'testdescription',
- re.search(self.re_description, raw_output).group(1))
+ cmd_output['description'],
+ )
- self.openstack(
+ raw_output = self.openstack(
'network flavor set --name ' + newname + ' --disable ' + name
)
- raw_output = self.openstack('network flavor show ' + newname)
+ self.assertOutput('', raw_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'network flavor show -f json ' + newname,))
self.assertEqual(
newname,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'False',
- re.search(self.re_enabled, raw_output).group(1))
+ False,
+ cmd_output['enabled'],
+ )
self.assertEqual(
'testdescription',
- re.search(self.re_description, raw_output).group(1))
+ cmd_output['description'],
+ )
def test_network_flavor_show(self):
+ """Test show network flavor"""
name = uuid.uuid4().hex
- self.openstack(
- 'network flavor create --description testdescription --enable'
- ' --service-type ' + self.SERVICE_TYPE + ' ' + name,
- )
+ cmd_output = json.loads(self.openstack(
+ 'network flavor create -f json --description testdescription '
+ '--disable --service-type L3_ROUTER_NAT ' + name,
+ ))
self.addCleanup(self.openstack, "network flavor delete " + name)
- raw_output = self.openstack('network flavor show ' + name)
+ cmd_output = json.loads(self.openstack(
+ 'network flavor show -f json ' + name,))
self.assertEqual(
name,
- re.search(self.re_name, raw_output).group(1))
+ cmd_output['name'],
+ )
self.assertEqual(
- 'True',
- re.search(self.re_enabled, raw_output).group(1))
+ False,
+ cmd_output['enabled'],
+ )
self.assertEqual(
'testdescription',
- re.search(self.re_description, raw_output).group(1))
+ cmd_output['description'],
+ )
diff --git a/openstackclient/tests/functional/network/v2/test_subnet.py b/openstackclient/tests/functional/network/v2/test_subnet.py
index 231671f3..995a4979 100644
--- a/openstackclient/tests/functional/network/v2/test_subnet.py
+++ b/openstackclient/tests/functional/network/v2/test_subnet.py
@@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import json
+import random
import uuid
from openstackclient.tests.functional import base
@@ -17,50 +19,242 @@ from openstackclient.tests.functional import base
class SubnetTests(base.TestCase):
"""Functional tests for subnet. """
- NAME = uuid.uuid4().hex
- NETWORK_NAME = uuid.uuid4().hex
- HEADERS = ['Name']
- FIELDS = ['name']
@classmethod
def setUpClass(cls):
- # Create a network for the subnet.
- cls.openstack('network create ' + cls.NETWORK_NAME)
- opts = cls.get_opts(cls.FIELDS)
- raw_output = cls.openstack(
- 'subnet create --network ' + cls.NETWORK_NAME +
- ' --subnet-range 10.10.10.0/24 ' +
- cls.NAME + opts
- )
- expected = cls.NAME + '\n'
- cls.assertOutput(expected, raw_output)
+ # Create a network for the all subnet tests.
+ cls.NETWORK_NAME = uuid.uuid4().hex
+ cmd_output = json.loads(cls.openstack(
+ 'network create -f json ' +
+ cls.NETWORK_NAME
+ ))
+ # Get network_id for assertEqual
+ cls.NETWORK_ID = cmd_output["id"]
@classmethod
def tearDownClass(cls):
- raw_output = cls.openstack('subnet delete ' + cls.NAME)
- cls.assertOutput('', raw_output)
raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME)
cls.assertOutput('', raw_output)
+ def test_subnet_create_and_delete(self):
+ """Test create, delete"""
+ name1 = uuid.uuid4().hex
+ cmd = ('subnet create -f json --network ' +
+ self.NETWORK_NAME +
+ ' --subnet-range')
+ cmd_output = self._subnet_create(cmd, name1)
+ self.assertEqual(
+ name1,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ self.NETWORK_ID,
+ cmd_output["network_id"],
+ )
+
+ del_output = self.openstack(
+ 'subnet delete ' + name1)
+ self.assertOutput('', del_output)
+
def test_subnet_list(self):
- opts = self.get_opts(self.HEADERS)
- raw_output = self.openstack('subnet list' + opts)
- self.assertIn(self.NAME, raw_output)
-
- def test_subnet_set(self):
- self.openstack('subnet set --no-dhcp ' + self.NAME)
- opts = self.get_opts(['name', 'enable_dhcp'])
- raw_output = self.openstack('subnet show ' + self.NAME + opts)
- self.assertEqual("False\n" + self.NAME + "\n", raw_output)
-
- def test_subnet_set_service_type(self):
- TYPE = 'network:floatingip_agent_gateway'
- self.openstack('subnet set --service-type ' + TYPE + ' ' + self.NAME)
- opts = self.get_opts(['name', 'service_types'])
- raw_output = self.openstack('subnet show ' + self.NAME + opts)
- self.assertEqual(self.NAME + "\n" + TYPE + "\n", raw_output)
-
- def test_subnet_show(self):
- opts = self.get_opts(self.FIELDS)
- raw_output = self.openstack('subnet show ' + self.NAME + opts)
- self.assertEqual(self.NAME + "\n", raw_output)
+ """Test create, list filter"""
+ name1 = uuid.uuid4().hex
+ name2 = uuid.uuid4().hex
+ cmd = ('subnet create -f json ' +
+ '--network ' + self.NETWORK_NAME +
+ ' --dhcp --subnet-range')
+ cmd_output = self._subnet_create(cmd, name1)
+ self.assertEqual(
+ name1,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ True,
+ cmd_output["enable_dhcp"],
+ )
+ self.assertEqual(
+ self.NETWORK_ID,
+ cmd_output["network_id"],
+ )
+ self.assertEqual(
+ 4,
+ cmd_output["ip_version"],
+ )
+
+ cmd = ('subnet create -f json ' +
+ '--network ' + self.NETWORK_NAME +
+ ' --ip-version 6 --no-dhcp ' +
+ '--subnet-range')
+ cmd_output = self._subnet_create(cmd, name2, is_type_ipv4=False)
+ self.assertEqual(
+ name2,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ False,
+ cmd_output["enable_dhcp"],
+ )
+ self.assertEqual(
+ self.NETWORK_ID,
+ cmd_output["network_id"],
+ )
+ self.assertEqual(
+ 6,
+ cmd_output["ip_version"],
+ )
+
+ # Test list --long
+ cmd_output = json.loads(self.openstack(
+ 'subnet list -f json ' +
+ '--long '
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test list --name
+ cmd_output = json.loads(self.openstack(
+ 'subnet list -f json ' +
+ '--name ' + name1
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertNotIn(name2, names)
+
+ # Test list --ip-version
+ cmd_output = json.loads(self.openstack(
+ 'subnet list -f json ' +
+ '--ip-version 6'
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertNotIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test list --network
+ cmd_output = json.loads(self.openstack(
+ 'subnet list -f json ' +
+ '--network ' + self.NETWORK_ID
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertIn(name1, names)
+ self.assertIn(name2, names)
+
+ # Test list --no-dhcp
+ cmd_output = json.loads(self.openstack(
+ 'subnet list -f json ' +
+ '--no-dhcp '
+ ))
+ names = [x["Name"] for x in cmd_output]
+ self.assertNotIn(name1, names)
+ self.assertIn(name2, names)
+
+ del_output = self.openstack(
+ 'subnet delete ' + name1 + ' ' + name2)
+ self.assertOutput('', del_output)
+
+ def test_subnet_set_show_unset(self):
+ """Test create subnet, set, unset, show, delete"""
+
+ name = uuid.uuid4().hex
+ new_name = name + "_"
+ cmd = ('subnet create -f json ' +
+ '--network ' + self.NETWORK_NAME +
+ ' --description aaaa --subnet-range')
+ cmd_output = self._subnet_create(cmd, name)
+ self.assertEqual(
+ name,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ 'aaaa',
+ cmd_output["description"],
+ )
+
+ # Test set --no-dhcp --name --gateway --description
+ cmd_output = self.openstack(
+ 'subnet set ' +
+ '--name ' + new_name +
+ ' --description bbbb ' +
+ '--no-dhcp ' +
+ '--gateway 10.10.11.1 ' +
+ '--service-type network:floatingip_agent_gateway ' +
+ name
+ )
+ self.assertOutput('', cmd_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'subnet show -f json ' +
+ new_name
+ ))
+ self.assertEqual(
+ new_name,
+ cmd_output["name"],
+ )
+ self.assertEqual(
+ 'bbbb',
+ cmd_output["description"],
+ )
+ self.assertEqual(
+ False,
+ cmd_output["enable_dhcp"],
+ )
+ self.assertEqual(
+ '10.10.11.1',
+ cmd_output["gateway_ip"],
+ )
+ self.assertEqual(
+ 'network:floatingip_agent_gateway',
+ cmd_output["service_types"],
+ )
+
+ # Test unset
+ cmd_output = self.openstack(
+ 'subnet unset ' +
+ '--service-type network:floatingip_agent_gateway ' +
+ new_name
+ )
+ self.assertOutput('', cmd_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'subnet show -f json ' +
+ new_name
+ ))
+ self.assertEqual(
+ '',
+ cmd_output["service_types"],
+ )
+
+ del_output = self.openstack(
+ 'subnet delete ' + new_name)
+ self.assertOutput('', del_output)
+
+ def _subnet_create(self, cmd, name, is_type_ipv4=True):
+ # Try random subnet range for subnet creating
+ # Because we can not determine ahead of time what subnets are already
+ # in use, possibly by another test running in parallel, try 4 times
+ for i in range(4):
+ # Make a random subnet
+ if is_type_ipv4:
+ subnet = ".".join(map(
+ str,
+ (random.randint(0, 223) for _ in range(3))
+ )) + ".0/26"
+ else:
+ subnet = ":".join(map(
+ str,
+ (hex(random.randint(0, 65535))[2:] for _ in range(7))
+ )) + ":0/112"
+ try:
+ cmd_output = json.loads(self.openstack(
+ cmd + ' ' + subnet + ' ' +
+ name
+ ))
+ except Exception:
+ if (i == 3):
+ # raise the exception at the last time
+ raise
+ pass
+ else:
+ # break and no longer retry if create sucessfully
+ break
+ return cmd_output
diff --git a/openstackclient/tests/functional/volume/v1/test_volume.py b/openstackclient/tests/functional/volume/v1/test_volume.py
index 992dfd66..3f04e071 100644
--- a/openstackclient/tests/functional/volume/v1/test_volume.py
+++ b/openstackclient/tests/functional/volume/v1/test_volume.py
@@ -141,8 +141,9 @@ class VolumeTests(common.BaseVolumeTests):
'--name ' + new_name +
' --size 2 ' +
'--description bbbb ' +
- '--property Alpha=c ' +
+ '--no-property ' +
'--property Beta=b ' +
+ '--property Gamma=c ' +
'--bootable ' +
name,
)
@@ -165,7 +166,7 @@ class VolumeTests(common.BaseVolumeTests):
cmd_output["display_description"],
)
self.assertEqual(
- "Alpha='c', Beta='b'",
+ "Beta='b', Gamma='c'",
cmd_output["properties"],
)
self.assertEqual(
@@ -176,7 +177,7 @@ class VolumeTests(common.BaseVolumeTests):
# Test volume unset
raw_output = self.openstack(
'volume unset ' +
- '--property Alpha ' +
+ '--property Beta ' +
new_name,
)
self.assertOutput('', raw_output)
@@ -186,7 +187,7 @@ class VolumeTests(common.BaseVolumeTests):
new_name
))
self.assertEqual(
- "Beta='b'",
+ "Gamma='c'",
cmd_output["properties"],
)
diff --git a/openstackclient/tests/functional/volume/v2/test_volume.py b/openstackclient/tests/functional/volume/v2/test_volume.py
index 203ca819..ce98236f 100644
--- a/openstackclient/tests/functional/volume/v2/test_volume.py
+++ b/openstackclient/tests/functional/volume/v2/test_volume.py
@@ -104,7 +104,7 @@ class VolumeTests(common.BaseVolumeTests):
# TODO(qiangjiahui): Add project option to filter tests when we can
# specify volume with project
- def test_volume_set(self):
+ def test_volume_set_and_unset(self):
"""Tests create volume, set, unset, show, delete"""
name = uuid.uuid4().hex
new_name = name + "_"
@@ -144,8 +144,11 @@ class VolumeTests(common.BaseVolumeTests):
'--name ' + new_name +
' --size 2 ' +
'--description bbbb ' +
- '--property Alpha=c ' +
+ '--no-property ' +
'--property Beta=b ' +
+ '--property Gamma=c ' +
+ '--image-property a=b ' +
+ '--image-property c=d ' +
'--bootable ' +
name,
)
@@ -168,10 +171,14 @@ class VolumeTests(common.BaseVolumeTests):
cmd_output["description"],
)
self.assertEqual(
- "Alpha='c', Beta='b'",
+ "Beta='b', Gamma='c'",
cmd_output["properties"],
)
self.assertEqual(
+ {'a': 'b', 'c': 'd'},
+ cmd_output["volume_image_metadata"],
+ )
+ self.assertEqual(
'true',
cmd_output["bootable"],
)
@@ -179,7 +186,8 @@ class VolumeTests(common.BaseVolumeTests):
# Test volume unset
raw_output = self.openstack(
'volume unset ' +
- '--property Alpha ' +
+ '--property Beta ' +
+ '--image-property a ' +
new_name,
)
self.assertOutput('', raw_output)
@@ -189,9 +197,13 @@ class VolumeTests(common.BaseVolumeTests):
new_name
))
self.assertEqual(
- "Beta='b'",
+ "Gamma='c'",
cmd_output["properties"],
)
+ self.assertEqual(
+ {'c': 'd'},
+ cmd_output["volume_image_metadata"],
+ )
def test_volume_snapshot(self):
"""Tests volume create from snapshot"""
diff --git a/openstackclient/tests/functional/volume/v3/__init__.py b/openstackclient/tests/functional/volume/v3/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/__init__.py
diff --git a/openstackclient/tests/functional/volume/v3/common.py b/openstackclient/tests/functional/volume/v3/common.py
new file mode 100644
index 00000000..57a62df6
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/common.py
@@ -0,0 +1,23 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import os
+
+from openstackclient.tests.functional import base
+
+
+class BaseVolumeTests(base.TestCase):
+ """Base class for Volume functional tests. """
+
+ @classmethod
+ def setUpClass(cls):
+ os.environ['OS_VOLUME_API_VERSION'] = '3'
diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py
new file mode 100644
index 00000000..46965ced
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/test_qos.py
@@ -0,0 +1,23 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from openstackclient.tests.functional.volume.v2 import test_qos as v2
+import os
+
+
+class QosTests(v2.QosTests):
+ """Functional tests for volume qos. """
+
+ @classmethod
+ def setUpClass(cls):
+ super(QosTests, cls).setUpClass()
+ os.environ['OS_VOLUME_API_VERSION'] = '3'
diff --git a/openstackclient/tests/functional/volume/v3/test_snapshot.py b/openstackclient/tests/functional/volume/v3/test_snapshot.py
new file mode 100644
index 00000000..bf05b9de
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/test_snapshot.py
@@ -0,0 +1,23 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from openstackclient.tests.functional.volume.v2 import test_snapshot as v2
+import os
+
+
+class VolumeSnapshotTests(v2.VolumeSnapshotTests):
+ """Functional tests for volume snapshot. """
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumeSnapshotTests, cls).setUpClass()
+ os.environ['OS_VOLUME_API_VERSION'] = '3'
diff --git a/openstackclient/tests/functional/volume/v3/test_transfer_request.py b/openstackclient/tests/functional/volume/v3/test_transfer_request.py
new file mode 100644
index 00000000..7b54dd20
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/test_transfer_request.py
@@ -0,0 +1,24 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from openstackclient.tests.functional.volume.v2 import test_transfer_request \
+ as v2
+import os
+
+
+class TransferRequestTests(v2.TransferRequestTests):
+ """Functional tests for transfer request. """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TransferRequestTests, cls).setUpClass()
+ os.environ['OS_VOLUME_API_VERSION'] = '3'
diff --git a/openstackclient/tests/functional/volume/v3/test_volume.py b/openstackclient/tests/functional/volume/v3/test_volume.py
new file mode 100644
index 00000000..333826d8
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/test_volume.py
@@ -0,0 +1,23 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from openstackclient.tests.functional.volume.v2 import test_volume as v2
+import os
+
+
+class VolumeTests(v2.VolumeTests):
+ """Functional tests for volume. """
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumeTests, cls).setUpClass()
+ os.environ['OS_VOLUME_API_VERSION'] = '3'
diff --git a/openstackclient/tests/functional/volume/v3/test_volume_type.py b/openstackclient/tests/functional/volume/v3/test_volume_type.py
new file mode 100644
index 00000000..f10e64b4
--- /dev/null
+++ b/openstackclient/tests/functional/volume/v3/test_volume_type.py
@@ -0,0 +1,23 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from openstackclient.tests.functional.volume.v2 import test_volume_type as v2
+import os
+
+
+class VolumeTypeTests(v2.VolumeTypeTests):
+ """Functional tests for volume type. """
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumeTypeTests, cls).setUpClass()
+ os.environ['OS_VOLUME_API_VERSION'] = '3'
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index 612dcab0..7afe3328 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -157,6 +157,31 @@ class FakeAddressScope(object):
return mock.Mock(side_effect=address_scopes)
+class FakeAutoAllocatedTopology(object):
+ """Fake Auto Allocated Topology"""
+
+ @staticmethod
+ def create_one_topology(attrs=None):
+ attrs = attrs or {}
+
+ auto_allocated_topology_attrs = {
+ 'id': 'network-id-' + uuid.uuid4().hex,
+ 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ }
+
+ auto_allocated_topology_attrs.update(attrs)
+
+ auto_allocated_topology = fakes.FakeResource(
+ info=copy.deepcopy(auto_allocated_topology_attrs),
+ loaded=True)
+
+ auto_allocated_topology.project_id = auto_allocated_topology_attrs[
+ 'tenant_id'
+ ]
+
+ return auto_allocated_topology
+
+
class FakeAvailabilityZone(object):
"""Fake one or more network availability zones (AZs)."""
diff --git a/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py b/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py
new file mode 100644
index 00000000..1a231160
--- /dev/null
+++ b/openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py
@@ -0,0 +1,267 @@
+# Copyright (c) 2016, Intel Corporation.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import mock
+
+from openstackclient.network.v2 import network_auto_allocated_topology
+from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
+from openstackclient.tests.unit.network.v2 import fakes as network_fakes
+
+
+class TestAutoAllocatedTopology(network_fakes.TestNetworkV2):
+ def setUp(self):
+ super(TestAutoAllocatedTopology, self).setUp()
+ self.network = self.app.client_manager.network
+ self.projects_mock = self.app.client_manager.identity.projects
+
+
+class TestCreateAutoAllocatedTopology(TestAutoAllocatedTopology):
+ project = identity_fakes.FakeProject.create_one_project()
+ network_object = network_fakes.FakeNetwork.create_one_network()
+
+ topology = network_fakes.FakeAutoAllocatedTopology.create_one_topology(
+ attrs={'id': network_object.id,
+ 'tenant_id': project.id}
+ )
+
+ columns = (
+ 'id',
+ 'project_id',
+ )
+
+ data = (
+ network_object.id,
+ project.id,
+ )
+
+ def setUp(self):
+ super(TestCreateAutoAllocatedTopology, self).setUp()
+
+ self.cmd = network_auto_allocated_topology.CreateAutoAllocatedTopology(
+ self.app,
+ self.namespace)
+ self.network.get_auto_allocated_topology = mock.Mock(
+ return_value=self.topology)
+
+ def test_create_no_options(self):
+ arglist = []
+ verifylist = []
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+ self.network.get_auto_allocated_topology.assert_called_with(None)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_project_option(self):
+ arglist = [
+ '--project', self.project.id,
+ ]
+
+ verifylist = [
+ ('project', self.project.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+ self.network.get_auto_allocated_topology.assert_called_with(
+ self.project.id
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_project_domain_option(self):
+ arglist = [
+ '--project', self.project.id,
+ '--project-domain', self.project.domain_id,
+ ]
+
+ verifylist = [
+ ('project', self.project.id),
+ ('project_domain', self.project.domain_id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+ self.network.get_auto_allocated_topology.assert_called_with(
+ self.project.id
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+ def test_create_or_show_option(self):
+ arglist = [
+ '--or-show',
+ ]
+
+ verifylist = [
+ ('or_show', True),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+ self.network.get_auto_allocated_topology.assert_called_with(None)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
+
+class TestValidateAutoAllocatedTopology(TestAutoAllocatedTopology):
+ project = identity_fakes.FakeProject.create_one_project()
+ network_object = network_fakes.FakeNetwork.create_one_network()
+
+ topology = network_fakes.FakeAutoAllocatedTopology.create_one_topology(
+ attrs={'id': network_object.id,
+ 'tenant_id': project.id}
+ )
+
+ columns = (
+ 'id',
+ 'project_id',
+ )
+
+ data = (
+ network_object.id,
+ project.id,
+ )
+
+ def setUp(self):
+ super(TestValidateAutoAllocatedTopology, self).setUp()
+
+ self.cmd = network_auto_allocated_topology.CreateAutoAllocatedTopology(
+ self.app,
+ self.namespace)
+ self.network.validate_auto_allocated_topology = mock.Mock(
+ return_value=self.topology)
+
+ def test_show_dry_run_no_project(self):
+ arglist = [
+ '--check-resources',
+ ]
+ verifylist = [
+ ('check_resources', True),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.validate_auto_allocated_topology.assert_called_with(
+ None)
+
+ def test_show_dry_run_project_option(self):
+ arglist = [
+ '--check-resources',
+ '--project', self.project.id,
+ ]
+ verifylist = [
+ ('check_resources', True),
+ ('project', self.project.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.validate_auto_allocated_topology.assert_called_with(
+ self.project.id)
+
+ def test_show_dry_run_project_domain_option(self):
+ arglist = [
+ '--check-resources',
+ '--project', self.project.id,
+ '--project-domain', self.project.domain_id,
+ ]
+ verifylist = [
+ ('check_resources', True),
+ ('project', self.project.id),
+ ('project_domain', self.project.domain_id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.validate_auto_allocated_topology.assert_called_with(
+ self.project.id)
+
+
+class TestDeleteAutoAllocatedTopology(TestAutoAllocatedTopology):
+ project = identity_fakes.FakeProject.create_one_project()
+ network_object = network_fakes.FakeNetwork.create_one_network()
+
+ topology = network_fakes.FakeAutoAllocatedTopology.create_one_topology(
+ attrs={'id': network_object.id,
+ 'tenant_id': project.id}
+ )
+
+ def setUp(self):
+ super(TestDeleteAutoAllocatedTopology, self).setUp()
+
+ self.cmd = network_auto_allocated_topology.DeleteAutoAllocatedTopology(
+ self.app,
+ self.namespace)
+ self.network.delete_auto_allocated_topology = mock.Mock(
+ return_value=None)
+
+ def test_delete_no_project(self):
+ arglist = []
+ verifylist = []
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ self.network.delete_auto_allocated_topology.assert_called_once_with(
+ None)
+
+ self.assertIsNone(result)
+
+ def test_delete_project_arg(self):
+ arglist = [
+ '--project', self.project.id,
+ ]
+ verifylist = [
+ ('project', self.project.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ self.network.delete_auto_allocated_topology.assert_called_once_with(
+ self.project.id)
+
+ self.assertIsNone(result)
+
+ def test_delete_project_domain_arg(self):
+ arglist = [
+ '--project', self.project.id,
+ '--project-domain', self.project.domain_id,
+ ]
+ verifylist = [
+ ('project', self.project.id),
+ ('project_domain', self.project.domain_id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ self.network.delete_auto_allocated_topology.assert_called_once_with(
+ self.project.id)
+
+ self.assertIsNone(result)
diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py
index 6c6d9a1d..d46a7ba9 100644
--- a/openstackclient/tests/unit/volume/v1/test_volume.py
+++ b/openstackclient/tests/unit/volume/v1/test_volume.py
@@ -1071,6 +1071,7 @@ class TestVolumeSet(TestVolume):
def test_volume_set_property(self):
arglist = [
+ '--no-property',
'--property', 'myprop=myvalue',
self._volume.display_name,
]
@@ -1080,6 +1081,7 @@ class TestVolumeSet(TestVolume):
('name', None),
('description', None),
('size', None),
+ ('no_property', True),
('property', {'myprop': 'myvalue'}),
('volume', self._volume.display_name),
('bootable', False),
@@ -1097,6 +1099,10 @@ class TestVolumeSet(TestVolume):
self._volume.id,
metadata
)
+ self.volumes_mock.delete_metadata.assert_called_with(
+ self._volume.id,
+ self._volume.metadata.keys()
+ )
self.volumes_mock.update_readonly_flag.assert_not_called()
self.assertIsNone(result)
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index 4fef9dd9..fbe719f3 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -1368,6 +1368,24 @@ class TestVolumeSet(TestVolume):
# Get the command object to test
self.cmd = volume.SetVolume(self.app, None)
+ def test_volume_set_property(self):
+ arglist = [
+ '--property', 'a=b',
+ '--property', 'c=d',
+ self.new_volume.id,
+ ]
+ verifylist = [
+ ('property', {'a': 'b', 'c': 'd'}),
+ ('volume', self.new_volume.id),
+ ('bootable', False),
+ ('non_bootable', False)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.cmd.take_action(parsed_args)
+ self.volumes_mock.set_metadata.assert_called_with(
+ self.new_volume.id, parsed_args.property)
+
def test_volume_set_image_property(self):
arglist = [
'--image-property', 'Alpha=a',
diff --git a/openstackclient/tests/unit/volume/v3/__init__.py b/openstackclient/tests/unit/volume/v3/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/openstackclient/tests/unit/volume/v3/__init__.py