summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/functional')
-rw-r--r--openstackclient/tests/functional/common/test_help.py8
-rw-r--r--openstackclient/tests/functional/compute/v2/common.py43
-rw-r--r--openstackclient/tests/functional/compute/v2/test_aggregate.py88
-rw-r--r--openstackclient/tests/functional/compute/v2/test_flavor.py114
-rw-r--r--openstackclient/tests/functional/compute/v2/test_hypervisor.py52
-rw-r--r--openstackclient/tests/functional/compute/v2/test_keypair.py8
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py647
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server_event.py44
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server_group.py55
-rw-r--r--openstackclient/tests/functional/identity/v3/test_project.py14
-rw-r--r--openstackclient/tests/functional/image/v1/test_image.py63
-rw-r--r--openstackclient/tests/functional/image/v2/test_image.py182
-rw-r--r--openstackclient/tests/functional/network/v2/common.py28
-rw-r--r--openstackclient/tests/functional/network/v2/test_address_group.py89
-rw-r--r--openstackclient/tests/functional/network/v2/test_address_scope.py74
-rw-r--r--openstackclient/tests/functional/network/v2/test_floating_ip.py125
-rw-r--r--openstackclient/tests/functional/network/v2/test_ip_availability.py20
-rw-r--r--openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py48
-rw-r--r--openstackclient/tests/functional/network/v2/test_local_ip.py83
-rw-r--r--openstackclient/tests/functional/network/v2/test_network.py174
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_agent.py70
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_flavor.py89
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_flavor_profile.py68
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_meter.py62
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_meter_rule.py60
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py130
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_qos_policy.py46
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_qos_rule.py167
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py43
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_rbac.py35
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_segment.py58
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_segment_range.py54
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_service_provider.py14
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_trunk.py149
-rw-r--r--openstackclient/tests/functional/network/v2/test_port.py154
-rw-r--r--openstackclient/tests/functional/network/v2/test_router.py154
-rw-r--r--openstackclient/tests/functional/network/v2/test_security_group.py24
-rw-r--r--openstackclient/tests/functional/network/v2/test_security_group_rule.py31
-rw-r--r--openstackclient/tests/functional/network/v2/test_subnet.py92
-rw-r--r--openstackclient/tests/functional/network/v2/test_subnet_pool.py59
-rw-r--r--openstackclient/tests/functional/volume/base.py11
-rw-r--r--openstackclient/tests/functional/volume/v1/test_qos.py53
-rw-r--r--openstackclient/tests/functional/volume/v1/test_service.py35
-rw-r--r--openstackclient/tests/functional/volume/v1/test_snapshot.py109
-rw-r--r--openstackclient/tests/functional/volume/v1/test_transfer_request.py57
-rw-r--r--openstackclient/tests/functional/volume/v1/test_volume.py145
-rw-r--r--openstackclient/tests/functional/volume/v1/test_volume_type.py106
-rw-r--r--openstackclient/tests/functional/volume/v2/test_qos.py116
-rw-r--r--openstackclient/tests/functional/volume/v2/test_service.py44
-rw-r--r--openstackclient/tests/functional/volume/v2/test_transfer_request.py62
-rw-r--r--openstackclient/tests/functional/volume/v2/test_volume.py136
-rw-r--r--openstackclient/tests/functional/volume/v2/test_volume_backup.py29
-rw-r--r--openstackclient/tests/functional/volume/v2/test_volume_snapshot.py118
-rw-r--r--openstackclient/tests/functional/volume/v2/test_volume_type.py120
-rw-r--r--openstackclient/tests/functional/volume/v3/test_qos.py116
-rw-r--r--openstackclient/tests/functional/volume/v3/test_transfer_request.py66
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume.py130
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume_snapshot.py109
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume_type.py120
59 files changed, 3006 insertions, 2194 deletions
diff --git a/openstackclient/tests/functional/common/test_help.py b/openstackclient/tests/functional/common/test_help.py
index c55741f1..e84c22e0 100644
--- a/openstackclient/tests/functional/common/test_help.py
+++ b/openstackclient/tests/functional/common/test_help.py
@@ -30,9 +30,7 @@ class HelpTests(base.TestCase):
('server image create',
'Create a new server disk image from an existing server'),
('server list', 'List servers'),
- ('server lock',
- 'Lock server(s). '
- 'A non-admin user will not be able to execute actions'),
+ ('server lock', 'Lock server(s)'),
('server migrate', 'Migrate server to different host'),
('server pause', 'Pause server(s)'),
('server reboot', 'Perform a hard or soft server reboot'),
@@ -46,8 +44,8 @@ class HelpTests(base.TestCase):
('server shelve', 'Shelve and optionally offload server(s)'),
('server show', 'Show server details'),
('server ssh', 'SSH to server'),
- ('server start', 'Start server(s).'),
- ('server stop', 'Stop server(s).'),
+ ('server start', 'Start server(s)'),
+ ('server stop', 'Stop server(s)'),
('server suspend', 'Suspend server(s)'),
('server unlock', 'Unlock server(s)'),
('server unpause', 'Unpause server(s)'),
diff --git a/openstackclient/tests/functional/compute/v2/common.py b/openstackclient/tests/functional/compute/v2/common.py
index 851664c8..7eca4603 100644
--- a/openstackclient/tests/functional/compute/v2/common.py
+++ b/openstackclient/tests/functional/compute/v2/common.py
@@ -11,7 +11,6 @@
# under the License.
#
-import json
import time
import uuid
@@ -38,9 +37,7 @@ class ComputeTestCase(base.TestCase):
def get_flavor(cls):
# NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional
# tests may create other flavors.
- flavors = json.loads(cls.openstack(
- "flavor list -f json "
- ))
+ flavors = cls.openstack("flavor list", parse_output=True)
server_flavor = None
for flavor in flavors:
if flavor['Name'] in ['m1.tiny', 'cirros256']:
@@ -53,9 +50,7 @@ class ComputeTestCase(base.TestCase):
# NOTE(rtheis): Get first Cirros image since functional tests may
# create other images. Image may be named '-uec' or
# '-disk'.
- images = json.loads(cls.openstack(
- "image list -f json "
- ))
+ images = cls.openstack("image list", parse_output=True)
server_image = None
for image in images:
if (image['Name'].startswith('cirros-') and
@@ -70,9 +65,10 @@ class ComputeTestCase(base.TestCase):
try:
# NOTE(rtheis): Get private network since functional tests may
# create other networks.
- cmd_output = json.loads(cls.openstack(
- 'network show private -f json'
- ))
+ cmd_output = cls.openstack(
+ 'network show private',
+ parse_output=True,
+ )
except exceptions.CommandFailed:
return ''
return '--nic net-id=' + cmd_output['id']
@@ -86,14 +82,15 @@ class ComputeTestCase(base.TestCase):
if not self.network_arg:
self.network_arg = self.get_network()
name = name or uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'server create -f json ' +
+ cmd_output = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
self.network_arg + ' ' +
'--wait ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
name,
@@ -120,10 +117,11 @@ class ComputeTestCase(base.TestCase):
failures = ['ERROR']
total_sleep = 0
while total_sleep < wait:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
status = cmd_output['status']
if status == expected_status:
print('Server {} now has status {}'.format(
@@ -135,10 +133,11 @@ class ComputeTestCase(base.TestCase):
time.sleep(interval)
total_sleep += interval
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
status = cmd_output['status']
self.assertEqual(status, expected_status)
# give it a little bit more time
diff --git a/openstackclient/tests/functional/compute/v2/test_aggregate.py b/openstackclient/tests/functional/compute/v2/test_aggregate.py
index 1de53099..80750faf 100644
--- a/openstackclient/tests/functional/compute/v2/test_aggregate.py
+++ b/openstackclient/tests/functional/compute/v2/test_aggregate.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional import base
@@ -27,12 +26,13 @@ class AggregateTests(base.TestCase):
'aggregate delete ' + name1,
fail_ok=True,
)
- cmd_output = json.loads(self.openstack(
- 'aggregate create -f json ' +
+ cmd_output = self.openstack(
+ 'aggregate create ' +
'--zone nova ' +
'--property a=b ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name']
@@ -45,8 +45,10 @@ class AggregateTests(base.TestCase):
'a',
cmd_output['properties']
)
- cmd_output = json.loads(self.openstack(
- 'aggregate show -f json ' + name1))
+ cmd_output = self.openstack(
+ 'aggregate show ' + name1,
+ parse_output=True,
+ )
self.assertEqual(name1, cmd_output['name'])
name2 = uuid.uuid4().hex
@@ -55,11 +57,12 @@ class AggregateTests(base.TestCase):
'aggregate delete ' + name2,
fail_ok=True,
)
- cmd_output = json.loads(self.openstack(
- 'aggregate create -f json ' +
+ cmd_output = self.openstack(
+ 'aggregate create ' +
'--zone external ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name']
@@ -68,8 +71,10 @@ class AggregateTests(base.TestCase):
'external',
cmd_output['availability_zone']
)
- cmd_output = json.loads(self.openstack(
- 'aggregate show -f json ' + name2))
+ cmd_output = self.openstack(
+ 'aggregate show ' + name2,
+ parse_output=True,
+ )
self.assertEqual(name2, cmd_output['name'])
# Test aggregate set
@@ -89,10 +94,11 @@ class AggregateTests(base.TestCase):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'aggregate show -f json ' +
- name3
- ))
+ cmd_output = self.openstack(
+ 'aggregate show ' +
+ name3,
+ parse_output=True,
+ )
self.assertEqual(
name3,
cmd_output['name']
@@ -111,9 +117,10 @@ class AggregateTests(base.TestCase):
)
# Test aggregate list
- cmd_output = json.loads(self.openstack(
- 'aggregate list -f json'
- ))
+ cmd_output = self.openstack(
+ 'aggregate list',
+ parse_output=True,
+ )
names = [x['Name'] for x in cmd_output]
self.assertIn(name3, names)
self.assertIn(name2, names)
@@ -122,9 +129,10 @@ class AggregateTests(base.TestCase):
self.assertIn('internal', zones)
# Test aggregate list --long
- cmd_output = json.loads(self.openstack(
- 'aggregate list --long -f json'
- ))
+ cmd_output = self.openstack(
+ 'aggregate list --long',
+ parse_output=True,
+ )
names = [x['Name'] for x in cmd_output]
self.assertIn(name3, names)
self.assertIn(name2, names)
@@ -143,10 +151,11 @@ class AggregateTests(base.TestCase):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'aggregate show -f json ' +
- name3
- ))
+ cmd_output = self.openstack(
+ 'aggregate show ' +
+ name3,
+ parse_output=True,
+ )
self.assertNotIn(
"c='d'",
cmd_output['properties']
@@ -163,9 +172,10 @@ class AggregateTests(base.TestCase):
def test_aggregate_add_and_remove_host(self):
"""Test aggregate add and remove host"""
# Get a host
- cmd_output = json.loads(self.openstack(
- 'host list -f json'
- ))
+ cmd_output = self.openstack(
+ 'host list',
+ parse_output=True,
+ )
host_name = cmd_output[0]['Host Name']
# NOTE(dtroyer): Cells v1 is not operable with aggregates. Hostnames
@@ -181,22 +191,24 @@ class AggregateTests(base.TestCase):
)
# Test add host
- cmd_output = json.loads(self.openstack(
- 'aggregate add host -f json ' +
+ cmd_output = self.openstack(
+ 'aggregate add host ' +
name + ' ' +
- host_name
- ))
+ host_name,
+ parse_output=True,
+ )
self.assertIn(
host_name,
cmd_output['hosts']
)
# Test remove host
- cmd_output = json.loads(self.openstack(
- 'aggregate remove host -f json ' +
+ cmd_output = self.openstack(
+ 'aggregate remove host ' +
name + ' ' +
- host_name
- ))
+ host_name,
+ parse_output=True,
+ )
self.assertNotIn(
host_name,
cmd_output['hosts']
diff --git a/openstackclient/tests/functional/compute/v2/test_flavor.py b/openstackclient/tests/functional/compute/v2/test_flavor.py
index 162d4287..98bf1ca5 100644
--- a/openstackclient/tests/functional/compute/v2/test_flavor.py
+++ b/openstackclient/tests/functional/compute/v2/test_flavor.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional import base
@@ -25,9 +24,10 @@ class FlavorTests(base.TestCase):
def setUpClass(cls):
super(FlavorTests, cls).setUpClass()
# Make a project
- cmd_output = json.loads(cls.openstack(
- "project create -f json --enable " + cls.PROJECT_NAME
- ))
+ cmd_output = cls.openstack(
+ "project create --enable " + cls.PROJECT_NAME,
+ parse_output=True,
+ )
cls.project_id = cmd_output["id"]
@classmethod
@@ -41,22 +41,24 @@ class FlavorTests(base.TestCase):
def test_flavor_delete(self):
"""Test create w/project, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- "flavor create -f json " +
+ cmd_output = self.openstack(
+ "flavor create " +
"--project " + self.PROJECT_NAME + " " +
"--private " +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- "flavor create -f json " +
+ cmd_output = self.openstack(
+ "flavor create " +
"--id qaz " +
"--project " + self.PROJECT_NAME + " " +
"--private " +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
"qaz",
@@ -71,12 +73,13 @@ class FlavorTests(base.TestCase):
def test_flavor_list(self):
"""Test create defaults, list filters, delete"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- "flavor create -f json " +
+ cmd_output = self.openstack(
+ "flavor create " +
"--property a=b " +
"--property c=d " +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, "flavor delete " + name1)
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
@@ -85,15 +88,16 @@ class FlavorTests(base.TestCase):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- "flavor create -f json " +
+ cmd_output = self.openstack(
+ "flavor create " +
"--id qaz " +
"--ram 123 " +
"--private " +
"--property a=b2 " +
"--property b=d2 " +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, "flavor delete " + name2)
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
@@ -121,18 +125,20 @@ class FlavorTests(base.TestCase):
)
# Test list
- cmd_output = json.loads(self.openstack(
- "flavor list -f json"
- ))
+ cmd_output = self.openstack(
+ "flavor list",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertNotIn(name2, col_name)
# Test list --long
- cmd_output = json.loads(self.openstack(
- "flavor list -f json " +
- "--long"
- ))
+ cmd_output = self.openstack(
+ "flavor list " +
+ "--long",
+ parse_output=True,
+ )
# We have list of complex json objects
# Iterate through the list setting flags
found_expected = False
@@ -147,28 +153,31 @@ class FlavorTests(base.TestCase):
self.assertTrue(found_expected)
# Test list --public
- cmd_output = json.loads(self.openstack(
- "flavor list -f json " +
- "--public"
- ))
+ cmd_output = self.openstack(
+ "flavor list " +
+ "--public",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertNotIn(name2, col_name)
# Test list --private
- cmd_output = json.loads(self.openstack(
- "flavor list -f json " +
- "--private"
- ))
+ cmd_output = self.openstack(
+ "flavor list " +
+ "--private",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, col_name)
self.assertIn(name2, col_name)
# Test list --all
- cmd_output = json.loads(self.openstack(
- "flavor list -f json " +
- "--all"
- ))
+ cmd_output = self.openstack(
+ "flavor list " +
+ "--all",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertIn(name2, col_name)
@@ -176,16 +185,17 @@ class FlavorTests(base.TestCase):
def test_flavor_properties(self):
"""Test create defaults, list filters, delete"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- "flavor create -f json " +
+ cmd_output = self.openstack(
+ "flavor create " +
"--id qaz " +
"--ram 123 " +
"--disk 20 " +
"--private " +
"--property a=first " +
"--property b=second " +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, "flavor delete " + name1)
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
@@ -220,10 +230,11 @@ class FlavorTests(base.TestCase):
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- "flavor show -f json " +
- name1
- ))
+ cmd_output = self.openstack(
+ "flavor show " +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
"qaz",
cmd_output["id"],
@@ -245,9 +256,10 @@ class FlavorTests(base.TestCase):
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- "flavor show -f json " +
- name1
- ))
+ cmd_output = self.openstack(
+ "flavor show " +
+ name1,
+ parse_output=True,
+ )
self.assertNotIn('b', cmd_output['properties'])
diff --git a/openstackclient/tests/functional/compute/v2/test_hypervisor.py b/openstackclient/tests/functional/compute/v2/test_hypervisor.py
new file mode 100644
index 00000000..9bc23280
--- /dev/null
+++ b/openstackclient/tests/functional/compute/v2/test_hypervisor.py
@@ -0,0 +1,52 @@
+# 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 json
+
+from openstackclient.tests.functional import base
+
+
+class HypervisorTests(base.TestCase):
+ """Functional tests for hypervisor."""
+
+ def test_hypervisor_list(self):
+ """Test create defaults, list filters, delete"""
+ # Test list
+ cmd_output = json.loads(self.openstack(
+ "hypervisor list -f json --os-compute-api-version 2.1"
+ ))
+ ids1 = [x["ID"] for x in cmd_output]
+ self.assertIsNotNone(cmd_output)
+
+ cmd_output = json.loads(self.openstack(
+ "hypervisor list -f json"
+ ))
+ ids2 = [x["ID"] for x in cmd_output]
+ self.assertIsNotNone(cmd_output)
+
+ # Show test - old microversion
+ for i in ids1:
+ cmd_output = json.loads(self.openstack(
+ "hypervisor show %s -f json "
+ " --os-compute-api-version 2.1"
+ % (i)
+ ))
+ self.assertIsNotNone(cmd_output)
+ # When we list hypervisors with older MV we get ids as integers. We
+ # need to verify that show finds resources independently
+ # Show test - latest microversion
+ for i in ids2:
+ cmd_output = json.loads(self.openstack(
+ "hypervisor show %s -f json"
+ % (i)
+ ))
+ self.assertIsNotNone(cmd_output)
diff --git a/openstackclient/tests/functional/compute/v2/test_keypair.py b/openstackclient/tests/functional/compute/v2/test_keypair.py
index 42f334a4..828d5dad 100644
--- a/openstackclient/tests/functional/compute/v2/test_keypair.py
+++ b/openstackclient/tests/functional/compute/v2/test_keypair.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import tempfile
from tempest.lib.common.utils import data_utils
@@ -109,9 +108,10 @@ class KeypairTests(KeypairBase):
2) Delete keypair
"""
with tempfile.NamedTemporaryFile(mode='w+') as f:
- cmd_output = json.loads(self.openstack(
- 'keypair create -f json --private-key %s tmpkey' % f.name,
- ))
+ cmd_output = self.openstack(
+ 'keypair create --private-key %s tmpkey' % f.name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'keypair delete tmpkey')
self.assertEqual('tmpkey', cmd_output.get('name'))
self.assertIsNotNone(cmd_output.get('user_id'))
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
index 0558ef62..05945a02 100644
--- a/openstackclient/tests/functional/compute/v2/test_server.py
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -39,9 +39,10 @@ class ServerTests(common.ComputeTestCase):
self.wait_for_status(name1, "ACTIVE")
self.wait_for_status(name2, "ACTIVE")
- cmd_output = json.loads(self.openstack(
- 'server list -f json'
- ))
+ cmd_output = self.openstack(
+ 'server list',
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertIn(name2, col_name)
@@ -50,17 +51,19 @@ class ServerTests(common.ComputeTestCase):
raw_output = self.openstack('server pause ' + name2)
self.assertEqual("", raw_output)
self.wait_for_status(name2, "PAUSED")
- cmd_output = json.loads(self.openstack(
- 'server list -f json ' +
- '--status ACTIVE'
- ))
+ cmd_output = self.openstack(
+ 'server list ' +
+ '--status ACTIVE',
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertNotIn(name2, col_name)
- cmd_output = json.loads(self.openstack(
- 'server list -f json ' +
- '--status PAUSED'
- ))
+ cmd_output = self.openstack(
+ 'server list ' +
+ '--status PAUSED',
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, col_name)
self.assertIn(name2, col_name)
@@ -76,16 +79,18 @@ class ServerTests(common.ComputeTestCase):
self.wait_for_status(name2, "ACTIVE")
# Test list --marker with ID
- cmd_output = json.loads(self.openstack(
- 'server list -f json --marker ' + id2
- ))
+ cmd_output = self.openstack(
+ 'server list --marker ' + id2,
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
# Test list --marker with Name
- cmd_output = json.loads(self.openstack(
- 'server list -f json --marker ' + name2
- ))
+ cmd_output = self.openstack(
+ 'server list --marker ' + name2,
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
@@ -93,19 +98,21 @@ class ServerTests(common.ComputeTestCase):
self.openstack('server delete --wait ' + name2)
# Test list --deleted --marker with ID
- cmd_output = json.loads(self.openstack(
- 'server list -f json --deleted --marker ' + id2
- ))
+ cmd_output = self.openstack(
+ 'server list --deleted --marker ' + id2,
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
# Test list --deleted --marker with Name
try:
- cmd_output = json.loads(self.openstack(
- 'server list -f json --deleted --marker ' + name2
- ))
+ cmd_output = self.openstack(
+ 'server list --deleted --marker ' + name2,
+ parse_output=True,
+ )
except exceptions.CommandFailed as e:
- self.assertIn('marker [%s] not found (HTTP 400)' % (name2),
+ self.assertIn('marker [%s] not found' % (name2),
e.stderr.decode('utf-8'))
def test_server_list_with_changes_before(self):
@@ -124,11 +131,12 @@ class ServerTests(common.ComputeTestCase):
cmd_output = self.server_create()
server_name3 = cmd_output['name']
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-compute-api-version 2.66 ' +
- 'server list -f json '
- '--changes-before ' + updated_at2
- ))
+ 'server list '
+ '--changes-before ' + updated_at2,
+ parse_output=True,
+ )
col_updated = [server["Name"] for server in cmd_output]
self.assertIn(server_name1, col_updated)
@@ -149,10 +157,11 @@ class ServerTests(common.ComputeTestCase):
cmd_output = self.server_create()
server_name3 = cmd_output['name']
- cmd_output = json.loads(self.openstack(
- 'server list -f json '
- '--changes-since ' + updated_at2
- ))
+ cmd_output = self.openstack(
+ 'server list '
+ '--changes-since ' + updated_at2,
+ parse_output=True,
+ )
col_updated = [server["Name"] for server in cmd_output]
self.assertNotIn(server_name1, col_updated)
@@ -174,12 +183,13 @@ class ServerTests(common.ComputeTestCase):
server_name3 = cmd_output['name']
updated_at3 = cmd_output['updated']
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-compute-api-version 2.66 ' +
- 'server list -f json ' +
+ 'server list ' +
'--changes-since ' + updated_at2 +
- ' --changes-before ' + updated_at3
- ))
+ ' --changes-before ' + updated_at3,
+ parse_output=True,
+ )
col_updated = [server["Name"] for server in cmd_output]
self.assertNotIn(server_name1, col_updated)
@@ -193,10 +203,11 @@ class ServerTests(common.ComputeTestCase):
# self.wait_for_status(name, "ACTIVE")
# Have a look at some other fields
- flavor = json.loads(self.openstack(
- 'flavor show -f json ' +
- self.flavor_name
- ))
+ flavor = self.openstack(
+ 'flavor show ' +
+ self.flavor_name,
+ parse_output=True,
+ )
self.assertEqual(
self.flavor_name,
flavor['name'],
@@ -205,10 +216,11 @@ class ServerTests(common.ComputeTestCase):
'%s (%s)' % (flavor['name'], flavor['id']),
cmd_output["flavor"],
)
- image = json.loads(self.openstack(
- 'image show -f json ' +
- self.image_name
- ))
+ image = self.openstack(
+ 'image show ' +
+ self.image_name,
+ parse_output=True,
+ )
self.assertEqual(
self.image_name,
image['name'],
@@ -226,10 +238,11 @@ class ServerTests(common.ComputeTestCase):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
# Really, shouldn't this be a list?
self.assertEqual(
{'a': 'b', 'c': 'd'},
@@ -241,10 +254,11 @@ class ServerTests(common.ComputeTestCase):
'--property a ' +
name
)
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
{'c': 'd'},
cmd_output['properties'],
@@ -258,10 +272,11 @@ class ServerTests(common.ComputeTestCase):
name
)
self.assertOutput("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -274,6 +289,33 @@ class ServerTests(common.ComputeTestCase):
)
self.assertOutput("", raw_output)
+ def test_server_show(self):
+ """Test server show"""
+ cmd_output = self.server_create()
+ name = cmd_output['name']
+
+ # Simple show
+ cmd_output = json.loads(self.openstack(
+ f'server show -f json {name}'
+ ))
+ self.assertEqual(
+ name,
+ cmd_output["name"],
+ )
+
+ # Show diagnostics
+ cmd_output = json.loads(self.openstack(
+ f'server show -f json {name} --diagnostics'
+ ))
+ self.assertIn('driver', cmd_output)
+
+ # Show topology
+ cmd_output = json.loads(self.openstack(
+ f'server show -f json {name} --topology '
+ f'--os-compute-api-version 2.78'
+ ))
+ self.assertIn('topology', cmd_output)
+
def test_server_actions(self):
"""Test server action pairs
@@ -360,10 +402,11 @@ class ServerTests(common.ComputeTestCase):
self.wait_for_status(name, "ACTIVE")
# attach ip
- cmd_output = json.loads(self.openstack(
- 'floating ip create -f json ' +
- 'public'
- ))
+ cmd_output = self.openstack(
+ 'floating ip create ' +
+ 'public',
+ parse_output=True,
+ )
# Look for Neutron value first, then nova-net
floating_ip = cmd_output.get(
@@ -392,10 +435,11 @@ class ServerTests(common.ComputeTestCase):
# racy we shouldn't have to wait too long, a minute seems reasonable
wait_time = 0
while wait_time < 60:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
if floating_ip not in _chain_addresses(cmd_output['addresses']):
# Hang out for a bit and try again
print('retrying floating IP check')
@@ -422,10 +466,11 @@ class ServerTests(common.ComputeTestCase):
# racy we shouldn't have to wait too long, a minute seems reasonable
wait_time = 0
while wait_time < 60:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
if floating_ip in _chain_addresses(cmd_output['addresses']):
# Hang out for a bit and try again
print('retrying floating IP check')
@@ -434,10 +479,11 @@ class ServerTests(common.ComputeTestCase):
else:
break
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
self.assertNotIn(
floating_ip,
_chain_addresses(cmd_output['addresses']),
@@ -459,10 +505,11 @@ class ServerTests(common.ComputeTestCase):
volume_wait_for = volume_common.BaseVolumeTests.wait_for_status
# get image size
- cmd_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.image_name
- ))
+ cmd_output = self.openstack(
+ 'image show ' +
+ self.image_name,
+ parse_output=True,
+ )
try:
image_size = cmd_output['min_disk']
if image_size < 1:
@@ -472,12 +519,13 @@ class ServerTests(common.ComputeTestCase):
# create volume from image
volume_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--image ' + self.image_name + ' ' +
'--size ' + str(image_size) + ' ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.addCleanup(self.openstack, 'volume delete ' + volume_name)
self.assertEqual(
@@ -488,11 +536,12 @@ class ServerTests(common.ComputeTestCase):
# create empty volume
empty_volume_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size ' + str(image_size) + ' ' +
- empty_volume_name
- ))
+ empty_volume_name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.addCleanup(self.openstack, 'volume delete ' + empty_volume_name)
self.assertEqual(
@@ -503,15 +552,16 @@ class ServerTests(common.ComputeTestCase):
# create server
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
- 'server create -f json ' +
+ server = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--volume ' + volume_name + ' ' +
'--block-device-mapping vdb=' + empty_volume_name + ' ' +
self.network_arg + ' ' +
'--wait ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(server["id"])
self.addCleanup(self.openstack, 'server delete --wait ' + server_name)
self.assertEqual(
@@ -525,19 +575,21 @@ class ServerTests(common.ComputeTestCase):
server['image'],
)
# check server list too
- servers = json.loads(self.openstack(
- 'server list -f json'
- ))
+ servers = self.openstack(
+ 'server list',
+ parse_output=True,
+ )
self.assertEqual(
v2_server.IMAGE_STRING_FOR_BFV,
servers[0]['Image']
)
# check volumes
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- volume_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ volume_name,
+ parse_output=True,
+ )
attachments = cmd_output['attachments']
self.assertEqual(
1,
@@ -556,10 +608,11 @@ class ServerTests(common.ComputeTestCase):
# --block-device-mapping was ignored if --volume
# present on the command line. Now we should see the
# attachment.
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- empty_volume_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ empty_volume_name,
+ parse_output=True,
+ )
attachments = cmd_output['attachments']
self.assertEqual(
1,
@@ -581,11 +634,12 @@ class ServerTests(common.ComputeTestCase):
# create source empty volume
volume_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
volume_id = cmd_output["id"]
self.assertIsNotNone(volume_id)
self.addCleanup(self.openstack, 'volume delete ' + volume_name)
@@ -603,15 +657,16 @@ class ServerTests(common.ComputeTestCase):
# create server
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
- 'server create -f json ' +
+ server = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
bdm_arg + ' ' +
self.network_arg + ' ' +
'--wait ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(server["id"])
self.addCleanup(self.openstack, 'server delete --wait ' + server_name)
self.assertEqual(
@@ -621,18 +676,20 @@ class ServerTests(common.ComputeTestCase):
# check server volumes_attached, format is
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ server_name,
+ parse_output=True,
+ )
volumes_attached = cmd_output['volumes_attached']
self.assertIsNotNone(volumes_attached)
# check volumes
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- volume_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ volume_name,
+ parse_output=True,
+ )
attachments = cmd_output['attachments']
self.assertEqual(
1,
@@ -665,11 +722,12 @@ class ServerTests(common.ComputeTestCase):
# create source empty volume
empty_volume_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- empty_volume_name
- ))
+ empty_volume_name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.addCleanup(self.openstack, 'volume delete ' + empty_volume_name)
self.assertEqual(empty_volume_name, cmd_output['name'])
@@ -677,11 +735,12 @@ class ServerTests(common.ComputeTestCase):
# create snapshot of source empty volume
empty_snapshot_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
'--volume ' + empty_volume_name + ' ' +
- empty_snapshot_name
- ))
+ empty_snapshot_name,
+ parse_output=True,
+ )
empty_snapshot_id = cmd_output["id"]
self.assertIsNotNone(empty_snapshot_id)
# Deleting volume snapshot take time, so we need to wait until the
@@ -712,15 +771,16 @@ class ServerTests(common.ComputeTestCase):
# create server with bdm snapshot
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
- 'server create -f json ' +
+ server = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
bdm_arg + ' ' +
self.network_arg + ' ' +
'--wait ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(server["id"])
self.assertEqual(
server_name,
@@ -730,19 +790,21 @@ class ServerTests(common.ComputeTestCase):
# check server volumes_attached, format is
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ server_name,
+ parse_output=True,
+ )
volumes_attached = cmd_output['volumes_attached']
self.assertIsNotNone(volumes_attached)
attached_volume_id = volumes_attached[0]["id"]
# check the volume that attached on server
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- attached_volume_id
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ attached_volume_id,
+ parse_output=True,
+ )
attachments = cmd_output['attachments']
self.assertEqual(
1,
@@ -760,9 +822,10 @@ class ServerTests(common.ComputeTestCase):
# delete server, then check the attached volume had been deleted,
# <delete-on-terminate>=true
self.openstack('server delete --wait ' + server_name)
- cmd_output = json.loads(self.openstack(
- 'volume list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume list',
+ parse_output=True,
+ )
target_volume = [each_volume
for each_volume in cmd_output
if each_volume['ID'] == attached_volume_id]
@@ -801,10 +864,11 @@ class ServerTests(common.ComputeTestCase):
)
else:
# get image ID
- cmd_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.image_name
- ))
+ cmd_output = self.openstack(
+ 'image show ' +
+ self.image_name,
+ parse_output=True,
+ )
image_id = cmd_output['id']
# This means create a 1GB volume from the specified image, attach
@@ -824,15 +888,16 @@ class ServerTests(common.ComputeTestCase):
# as expected where nova creates a volume from the image and attaches
# that volume to the server.
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
- 'server create -f json ' +
+ server = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
bdm_arg + ' ' +
self.network_arg + ' ' +
'--wait ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(server["id"])
self.assertEqual(
server_name,
@@ -842,19 +907,21 @@ class ServerTests(common.ComputeTestCase):
# check server volumes_attached, format is
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ server_name,
+ parse_output=True,
+ )
volumes_attached = cmd_output['volumes_attached']
self.assertIsNotNone(volumes_attached)
attached_volume_id = volumes_attached[0]["id"]
# check the volume that attached on server
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- attached_volume_id
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ attached_volume_id,
+ parse_output=True,
+ )
attachments = cmd_output['attachments']
self.assertEqual(
1,
@@ -879,9 +946,10 @@ class ServerTests(common.ComputeTestCase):
# delete server, then check the attached volume has been deleted
self.openstack('server delete --wait ' + server_name)
- cmd_output = json.loads(self.openstack(
- 'volume list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume list',
+ parse_output=True,
+ )
target_volume = [each_volume
for each_volume in cmd_output
if each_volume['ID'] == attached_volume_id]
@@ -906,15 +974,16 @@ class ServerTests(common.ComputeTestCase):
# using the provided image, attach it as the root disk for the server
# and not delete the volume when the server is deleted.
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
- 'server create -f json ' +
+ server = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
'--boot-from-volume 1 ' + # create a 1GB volume from the image
self.network_arg + ' ' +
'--wait ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(server["id"])
self.assertEqual(
server_name,
@@ -924,10 +993,11 @@ class ServerTests(common.ComputeTestCase):
# check server volumes_attached, format is
# {"volumes_attached": "id='2518bc76-bf0b-476e-ad6b-571973745bb5'",}
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ server_name,
+ parse_output=True,
+ )
volumes_attached = cmd_output['volumes_attached']
self.assertIsNotNone(volumes_attached)
attached_volume_id = volumes_attached[0]["id"]
@@ -941,10 +1011,11 @@ class ServerTests(common.ComputeTestCase):
self.assertEqual(v2_server.IMAGE_STRING_FOR_BFV, cmd_output['image'])
# check the volume that attached on server
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- volumes_attached[0]["id"]
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ volumes_attached[0]["id"],
+ parse_output=True,
+ )
# The volume size should be what we specified on the command line.
self.assertEqual(1, int(cmd_output['size']))
attachments = cmd_output['attachments']
@@ -971,32 +1042,35 @@ class ServerTests(common.ComputeTestCase):
# delete server, then check the attached volume was not deleted
self.openstack('server delete --wait ' + server_name)
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- attached_volume_id
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ attached_volume_id,
+ parse_output=True,
+ )
# check the volume is in 'available' status
self.assertEqual('available', cmd_output['status'])
def test_server_create_with_none_network(self):
"""Test server create with none network option."""
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
+ server = self.openstack(
# auto/none enable in nova micro version (v2.37+)
'--os-compute-api-version 2.37 ' +
- 'server create -f json ' +
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
'--nic none ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(server["id"])
self.addCleanup(self.openstack, 'server delete --wait ' + server_name)
self.assertEqual(server_name, server['name'])
self.wait_for_status(server_name, "ACTIVE")
- server = json.loads(self.openstack(
- 'server show -f json ' + server_name
- ))
+ server = self.openstack(
+ 'server show ' + server_name,
+ parse_output=True,
+ )
self.assertEqual({}, server['addresses'])
def test_server_create_with_security_group(self):
@@ -1011,27 +1085,30 @@ class ServerTests(common.ComputeTestCase):
self.skipTest("No Network service present")
# Create two security group, use name and ID to create server
sg_name1 = uuid.uuid4().hex
- security_group1 = json.loads(self.openstack(
- 'security group create -f json ' + sg_name1
- ))
+ security_group1 = self.openstack(
+ 'security group create ' + sg_name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'security group delete ' + sg_name1)
sg_name2 = uuid.uuid4().hex
- security_group2 = json.loads(self.openstack(
- 'security group create -f json ' + sg_name2
- ))
+ security_group2 = self.openstack(
+ 'security group create ' + sg_name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'security group delete ' + sg_name2)
server_name = uuid.uuid4().hex
- server = json.loads(self.openstack(
- 'server create -f json ' +
+ server = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
# Security group id is integer in nova-network, convert to string
'--security-group ' + str(security_group1['id']) + ' ' +
'--security-group ' + security_group2['name'] + ' ' +
self.network_arg + ' ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'server delete --wait ' + server_name)
self.assertIsNotNone(server['id'])
@@ -1042,9 +1119,10 @@ class ServerTests(common.ComputeTestCase):
self.assertIn(str(security_group1['id']), sec_grp)
self.assertIn(str(security_group2['id']), sec_grp)
self.wait_for_status(server_name, 'ACTIVE')
- server = json.loads(self.openstack(
- 'server show -f json ' + server_name
- ))
+ server = self.openstack(
+ 'server show ' + server_name,
+ parse_output=True,
+ )
# check if security group exists in list
sec_grp = ""
for sec in server['security_groups']:
@@ -1059,7 +1137,7 @@ class ServerTests(common.ComputeTestCase):
self.openstack(
# auto/none enable in nova micro version (v2.37+)
'--os-compute-api-version 2.37 ' +
- 'server create -f json ' +
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
server_name
@@ -1074,14 +1152,15 @@ class ServerTests(common.ComputeTestCase):
def test_server_add_remove_network(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'server create -f json ' +
+ cmd_output = self.openstack(
+ 'server create ' +
'--network private ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
'--wait ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output['id'])
self.assertEqual(name, cmd_output['name'])
@@ -1093,9 +1172,10 @@ class ServerTests(common.ComputeTestCase):
wait_time = 0
while wait_time < 60:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' + name
- ))
+ cmd_output = self.openstack(
+ 'server show ' + name,
+ parse_output=True,
+ )
if 'public' not in cmd_output['addresses']:
# Hang out for a bit and try again
print('retrying add network check')
@@ -1111,9 +1191,10 @@ class ServerTests(common.ComputeTestCase):
wait_time = 0
while wait_time < 60:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' + name
- ))
+ cmd_output = self.openstack(
+ 'server show ' + name,
+ parse_output=True,
+ )
if 'public' in cmd_output['addresses']:
# Hang out for a bit and try again
print('retrying remove network check')
@@ -1127,14 +1208,15 @@ class ServerTests(common.ComputeTestCase):
def test_server_add_remove_port(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'server create -f json ' +
+ cmd_output = self.openstack(
+ 'server create ' +
'--network private ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
'--wait ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output['id'])
self.assertEqual(name, cmd_output['name'])
@@ -1143,15 +1225,17 @@ class ServerTests(common.ComputeTestCase):
# create port, record one of its ip address
port_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'port list -f json'
- ))
+ cmd_output = self.openstack(
+ 'port list',
+ parse_output=True,
+ )
self.assertNotIn(port_name, cmd_output)
- cmd_output = json.loads(self.openstack(
- 'port create -f json ' +
- '--network private ' + port_name
- ))
+ cmd_output = self.openstack(
+ 'port create ' +
+ '--network private ' + port_name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output['id'])
ip_address = cmd_output['fixed_ips'][0]['ip_address']
self.addCleanup(self.openstack, 'port delete ' + port_name)
@@ -1161,9 +1245,10 @@ class ServerTests(common.ComputeTestCase):
wait_time = 0
while wait_time < 60:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' + name
- ))
+ cmd_output = self.openstack(
+ 'server show ' + name,
+ parse_output=True,
+ )
if ip_address not in cmd_output['addresses']['private']:
# Hang out for a bit and try again
print('retrying add port check')
@@ -1179,9 +1264,10 @@ class ServerTests(common.ComputeTestCase):
wait_time = 0
while wait_time < 60:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' + name
- ))
+ cmd_output = self.openstack(
+ 'server show ' + name,
+ parse_output=True,
+ )
if ip_address in cmd_output['addresses']['private']:
# Hang out for a bit and try again
print('retrying add port check')
@@ -1192,18 +1278,75 @@ class ServerTests(common.ComputeTestCase):
addresses = cmd_output['addresses']['private']
self.assertNotIn(ip_address, addresses)
+ def test_server_add_fixed_ip(self):
+ name = uuid.uuid4().hex
+ cmd_output = self.openstack(
+ 'server create ' +
+ '--network private ' +
+ '--flavor ' + self.flavor_name + ' ' +
+ '--image ' + self.image_name + ' ' +
+ '--wait ' +
+ name,
+ parse_output=True,
+ )
+
+ self.assertIsNotNone(cmd_output['id'])
+ self.assertEqual(name, cmd_output['name'])
+ self.addCleanup(self.openstack, 'server delete --wait ' + name)
+
+ # create port, record its ip address to use in later call,
+ # then delete - this is to figure out what should be a free ip
+ # in the subnet
+ port_name = uuid.uuid4().hex
+
+ cmd_output = self.openstack(
+ 'port list',
+ parse_output=True,
+ )
+ self.assertNotIn(port_name, cmd_output)
+
+ cmd_output = self.openstack(
+ 'port create ' +
+ '--network private ' + port_name,
+ parse_output=True,
+ )
+ self.assertIsNotNone(cmd_output['id'])
+ ip_address = cmd_output['fixed_ips'][0]['ip_address']
+ self.openstack('port delete ' + port_name)
+
+ # add fixed ip to server, assert the ip address appears
+ self.openstack('server add fixed ip --fixed-ip-address ' + ip_address +
+ ' ' + name + ' private')
+
+ wait_time = 0
+ while wait_time < 60:
+ cmd_output = self.openstack(
+ 'server show ' + name,
+ parse_output=True,
+ )
+ if ip_address not in cmd_output['addresses']['private']:
+ # Hang out for a bit and try again
+ print('retrying add fixed ip check')
+ wait_time += 10
+ time.sleep(10)
+ else:
+ break
+ addresses = cmd_output['addresses']['private']
+ self.assertIn(ip_address, addresses)
+
def test_server_add_remove_volume(self):
volume_wait_for = volume_common.BaseVolumeTests.wait_for_status
server_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'server create -f json ' +
+ cmd_output = self.openstack(
+ 'server create ' +
'--network private ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
'--wait ' +
- server_name
- ))
+ server_name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output['id'])
self.assertEqual(server_name, cmd_output['name'])
@@ -1211,11 +1354,12 @@ class ServerTests(common.ComputeTestCase):
server_id = cmd_output['id']
volume_name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output['id'])
self.assertEqual(volume_name, cmd_output['name'])
@@ -1223,33 +1367,33 @@ class ServerTests(common.ComputeTestCase):
self.addCleanup(self.openstack, 'volume delete ' + volume_name)
volume_id = cmd_output['id']
- cmd_output = json.loads(self.openstack(
- 'server add volume -f json ' +
+ cmd_output = self.openstack(
+ 'server add volume ' +
server_name + ' ' +
volume_name + ' ' +
- '--tag bar'
- ))
+ '--tag bar',
+ parse_output=True,
+ )
- self.assertIsNotNone(cmd_output['ID'])
self.assertEqual(server_id, cmd_output['Server ID'])
self.assertEqual(volume_id, cmd_output['Volume ID'])
- volume_attachment_id = cmd_output['ID']
- cmd_output = json.loads(self.openstack(
- 'server volume list -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server volume list ' +
+ server_name,
+ parse_output=True,
+ )
- self.assertEqual(volume_attachment_id, cmd_output[0]['ID'])
self.assertEqual(server_id, cmd_output[0]['Server ID'])
self.assertEqual(volume_id, cmd_output[0]['Volume ID'])
volume_wait_for('volume', volume_name, 'in-use')
- cmd_output = json.loads(self.openstack(
- 'server event list -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server event list ' +
+ server_name,
+ parse_output=True,
+ )
self.assertEqual(2, len(cmd_output))
self.assertIn('attach_volume', {x['Action'] for x in cmd_output})
@@ -1258,12 +1402,19 @@ class ServerTests(common.ComputeTestCase):
)
volume_wait_for('volume', volume_name, 'available')
- cmd_output = json.loads(self.openstack(
- 'server event list -f json ' +
- server_name
- ))
+ cmd_output = self.openstack(
+ 'server event list ' +
+ server_name,
+ parse_output=True,
+ )
self.assertEqual(3, len(cmd_output))
self.assertIn('detach_volume', {x['Action'] for x in cmd_output})
raw_output = self.openstack('server volume list ' + server_name)
self.assertEqual('\n', raw_output)
+
+ def test_server_migration_list(self):
+ # Verify that the command does not raise an exception when we list
+ # migrations, including when we specify a query.
+ self.openstack('server migration list')
+ self.openstack('server migration list --limit 1')
diff --git a/openstackclient/tests/functional/compute/v2/test_server_event.py b/openstackclient/tests/functional/compute/v2/test_server_event.py
index b4725fe6..48147507 100644
--- a/openstackclient/tests/functional/compute/v2/test_server_event.py
+++ b/openstackclient/tests/functional/compute/v2/test_server_event.py
@@ -13,8 +13,6 @@
# under the License.
#
-import json
-
from openstackclient.tests.functional.compute.v2 import common
@@ -33,9 +31,10 @@ class ServerEventTests(common.ComputeTestCase):
def test_server_event_list_and_show(self):
"""Test list, show server event"""
# Test 'server event list' for creating
- cmd_output = json.loads(self.openstack(
- 'server event list -f json ' + self.server_name
- ))
+ cmd_output = self.openstack(
+ 'server event list ' + self.server_name,
+ parse_output=True,
+ )
request_id = None
for each_event in cmd_output:
self.assertNotIn('Message', each_event)
@@ -47,9 +46,10 @@ class ServerEventTests(common.ComputeTestCase):
break
self.assertIsNotNone(request_id)
# Test 'server event show' for creating
- cmd_output = json.loads(self.openstack(
- 'server event show -f json ' + self.server_name + ' ' + request_id
- ))
+ cmd_output = self.openstack(
+ 'server event show ' + self.server_name + ' ' + request_id,
+ parse_output=True,
+ )
self.assertEqual(self.server_id, cmd_output.get('instance_uuid'))
self.assertEqual(request_id, cmd_output.get('request_id'))
self.assertEqual('create', cmd_output.get('action'))
@@ -59,9 +59,10 @@ class ServerEventTests(common.ComputeTestCase):
# Reboot server, trigger reboot event
self.openstack('server reboot --wait ' + self.server_name)
# Test 'server event list --long' for rebooting
- cmd_output = json.loads(self.openstack(
- 'server event list --long -f json ' + self.server_name
- ))
+ cmd_output = self.openstack(
+ 'server event list --long ' + self.server_name,
+ parse_output=True,
+ )
request_id = None
for each_event in cmd_output:
self.assertIn('Message', each_event)
@@ -73,9 +74,10 @@ class ServerEventTests(common.ComputeTestCase):
break
self.assertIsNotNone(request_id)
# Test 'server event show' for rebooting
- cmd_output = json.loads(self.openstack(
- 'server event show -f json ' + self.server_name + ' ' + request_id
- ))
+ cmd_output = self.openstack(
+ 'server event show ' + self.server_name + ' ' + request_id,
+ parse_output=True,
+ )
self.assertEqual(self.server_id, cmd_output.get('instance_uuid'))
self.assertEqual(request_id, cmd_output.get('request_id'))
@@ -93,10 +95,11 @@ class ServerEventTests(common.ComputeTestCase):
self.openstack('server delete --wait ' + server_id)
# And verify we can get the event list after it's deleted
# Test 'server event list' for deleting
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-compute-api-version 2.21 '
- 'server event list -f json ' + server_id
- ))
+ 'server event list ' + server_id,
+ parse_output=True,
+ )
request_id = None
for each_event in cmd_output:
self.assertNotIn('Message', each_event)
@@ -108,10 +111,11 @@ class ServerEventTests(common.ComputeTestCase):
break
self.assertIsNotNone(request_id)
# Test 'server event show' for deleting
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-compute-api-version 2.21 '
- 'server event show -f json ' + server_id + ' ' + request_id
- ))
+ 'server event show ' + server_id + ' ' + request_id,
+ parse_output=True,
+ )
self.assertEqual(server_id, cmd_output.get('instance_uuid'))
self.assertEqual(request_id, cmd_output.get('request_id'))
self.assertEqual('delete', cmd_output.get('action'))
diff --git a/openstackclient/tests/functional/compute/v2/test_server_group.py b/openstackclient/tests/functional/compute/v2/test_server_group.py
index daeecd2d..a599951c 100644
--- a/openstackclient/tests/functional/compute/v2/test_server_group.py
+++ b/openstackclient/tests/functional/compute/v2/test_server_group.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional import base
@@ -23,11 +22,12 @@ class ServerGroupTests(base.TestCase):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'server group create -f json ' +
+ cmd_output = self.openstack(
+ 'server group create ' +
'--policy affinity ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name']
@@ -37,11 +37,12 @@ class ServerGroupTests(base.TestCase):
cmd_output['policy']
)
- cmd_output = json.loads(self.openstack(
- 'server group create -f json ' +
+ cmd_output = self.openstack(
+ 'server group create ' +
'--policy anti-affinity ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name']
@@ -61,14 +62,17 @@ class ServerGroupTests(base.TestCase):
name2 = uuid.uuid4().hex
# test server group show
- cmd_output = json.loads(self.openstack(
- 'server group create -f json ' +
+ cmd_output = self.openstack(
+ 'server group create ' +
'--policy affinity ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'server group delete ' + name1)
- cmd_output = json.loads(self.openstack(
- 'server group show -f json ' + name1))
+ cmd_output = self.openstack(
+ 'server group show ' + name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name']
@@ -78,14 +82,17 @@ class ServerGroupTests(base.TestCase):
cmd_output['policy']
)
- cmd_output = json.loads(self.openstack(
- 'server group create -f json ' +
+ cmd_output = self.openstack(
+ 'server group create ' +
'--policy anti-affinity ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'server group delete ' + name2)
- cmd_output = json.loads(self.openstack(
- 'server group show -f json ' + name2))
+ cmd_output = self.openstack(
+ 'server group show ' + name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name']
@@ -96,8 +103,10 @@ class ServerGroupTests(base.TestCase):
)
# test server group list
- cmd_output = json.loads(self.openstack(
- 'server group list -f json'))
+ cmd_output = self.openstack(
+ 'server group list',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
diff --git a/openstackclient/tests/functional/identity/v3/test_project.py b/openstackclient/tests/functional/identity/v3/test_project.py
index 27cf4481..b3d31aa7 100644
--- a/openstackclient/tests/functional/identity/v3/test_project.py
+++ b/openstackclient/tests/functional/identity/v3/test_project.py
@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from tempest.lib.common.utils import data_utils
from openstackclient.tests.functional.identity.v3 import common
@@ -114,12 +112,14 @@ class ProjectTests(common.IdentityTests):
self.assert_show_fields(items, self.PROJECT_FIELDS)
def test_project_show_with_parents_children(self):
- json_output = json.loads(self.openstack(
+ output = self.openstack(
'project show '
- '--parents --children -f json '
+ '--parents --children '
'--domain %(domain)s '
'%(name)s' % {'domain': self.domain_name,
- 'name': self.project_name}))
+ 'name': self.project_name},
+ parse_output=True,
+ )
for attr_name in (self.PROJECT_FIELDS + ['parents', 'subtree']):
- self.assertIn(attr_name, json_output)
- self.assertEqual(self.project_name, json_output.get('name'))
+ self.assertIn(attr_name, output)
+ self.assertEqual(self.project_name, output.get('name'))
diff --git a/openstackclient/tests/functional/image/v1/test_image.py b/openstackclient/tests/functional/image/v1/test_image.py
index b9774ab5..2b4d8f41 100644
--- a/openstackclient/tests/functional/image/v1/test_image.py
+++ b/openstackclient/tests/functional/image/v1/test_image.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
import fixtures
@@ -22,41 +21,37 @@ class ImageTests(base.BaseImageTests):
"""Functional tests for Image commands"""
def setUp(self):
- super(ImageTests, self).setUp()
+ super().setUp()
+
if not self.haz_v1_api:
self.skipTest('No Image v1 API present')
- self.name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- '--os-image-api-version 1 '
- 'image create -f json ' +
- self.name
- ))
- self.image_id = json_output["id"]
- self.assertOutput(self.name, json_output['name'])
-
ver_fixture = fixtures.EnvironmentVariable(
'OS_IMAGE_API_VERSION', '1'
)
self.useFixture(ver_fixture)
+ self.name = uuid.uuid4().hex
+ output = self.openstack(
+ 'image create ' + self.name,
+ parse_output=True,
+ )
+ self.image_id = output["id"]
+ self.assertOutput(self.name, output['name'])
+
def tearDown(self):
try:
- self.openstack(
- '--os-image-api-version 1 '
- 'image delete ' +
- self.image_id
- )
+ self.openstack('image delete ' + self.image_id)
finally:
- super(ImageTests, self).tearDown()
+ super().tearDown()
def test_image_list(self):
- json_output = json.loads(self.openstack(
- 'image list -f json '
- ))
+ output = self.openstack(
+ 'image list'
+ )
self.assertIn(
self.name,
- [img['Name'] for img in json_output]
+ [img['Name'] for img in output]
)
def test_image_attributes(self):
@@ -71,24 +66,24 @@ class ImageTests(base.BaseImageTests):
'--public ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
self.assertEqual(
4,
- json_output["min_disk"],
+ output["min_disk"],
)
self.assertEqual(
5,
- json_output["min_ram"],
+ output["min_ram"],
)
self.assertEqual(
'qcow2',
- json_output['disk_format'],
+ output['disk_format'],
)
self.assertTrue(
- json_output["is_public"],
+ output["is_public"],
)
# Test properties
@@ -99,11 +94,11 @@ class ImageTests(base.BaseImageTests):
'--public ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
self.assertEqual(
{'a': 'b', 'c': 'd'},
- json_output["properties"],
+ output["properties"],
)
diff --git a/openstackclient/tests/functional/image/v2/test_image.py b/openstackclient/tests/functional/image/v2/test_image.py
index 5b074700..3535bd7e 100644
--- a/openstackclient/tests/functional/image/v2/test_image.py
+++ b/openstackclient/tests/functional/image/v2/test_image.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
import fixtures
@@ -24,65 +23,62 @@ class ImageTests(base.BaseImageTests):
def setUp(self):
super(ImageTests, self).setUp()
- self.name = uuid.uuid4().hex
- self.image_tag = 'my_tag'
- self.image_tag1 = 'random'
- json_output = json.loads(self.openstack(
- '--os-image-api-version 2 '
- 'image create -f json --tag {tag} {name}'.format(
- tag=self.image_tag, name=self.name)
- ))
- self.image_id = json_output["id"]
- self.assertOutput(self.name, json_output['name'])
-
ver_fixture = fixtures.EnvironmentVariable(
'OS_IMAGE_API_VERSION', '2'
)
self.useFixture(ver_fixture)
+ self.name = uuid.uuid4().hex
+ self.image_tag = 'my_tag'
+ self.image_tag1 = 'random'
+ output = self.openstack(
+ 'image create --tag {tag} {name}'.format(
+ tag=self.image_tag, name=self.name),
+ parse_output=True,
+ )
+ self.image_id = output["id"]
+ self.assertOutput(self.name, output['name'])
+
def tearDown(self):
try:
- self.openstack(
- '--os-image-api-version 2 '
- 'image delete ' +
- self.image_id
- )
+ self.openstack('image delete ' + self.image_id)
finally:
- super(ImageTests, self).tearDown()
+ super().tearDown()
def test_image_list(self):
- json_output = json.loads(self.openstack(
- 'image list -f json '
- ))
+ output = self.openstack('image list', parse_output=True)
self.assertIn(
self.name,
- [img['Name'] for img in json_output]
+ [img['Name'] for img in output]
)
def test_image_list_with_name_filter(self):
- json_output = json.loads(self.openstack(
- 'image list --name ' + self.name + ' -f json'
- ))
+ output = self.openstack(
+ 'image list --name ' + self.name,
+ parse_output=True,
+ )
self.assertIn(
self.name,
- [img['Name'] for img in json_output]
+ [img['Name'] for img in output]
)
def test_image_list_with_status_filter(self):
- json_output = json.loads(self.openstack(
- 'image list ' + ' --status active -f json'
- ))
+ output = self.openstack(
+ 'image list --status active',
+ parse_output=True,
+ )
self.assertIn(
'active',
- [img['Status'] for img in json_output]
+ [img['Status'] for img in output]
)
def test_image_list_with_tag_filter(self):
- json_output = json.loads(self.openstack(
+ output = self.openstack(
'image list --tag ' + self.image_tag + ' --tag ' +
- self.image_tag1 + ' --long -f json'
- ))
- for taglist in [img['Tags'] for img in json_output]:
+ self.image_tag1 + ' --long',
+ parse_output=True,
+ )
+ for taglist in [img['Tags'] for img in output]:
self.assertIn(
self.image_tag,
taglist
@@ -103,21 +99,21 @@ class ImageTests(base.BaseImageTests):
'--public ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
self.assertEqual(
4,
- json_output["min_disk"],
+ output["min_disk"],
)
self.assertEqual(
5,
- json_output["min_ram"],
+ output["min_ram"],
)
self.assertEqual(
'public',
- json_output["visibility"],
+ output["visibility"],
)
# Test properties
@@ -129,12 +125,12 @@ class ImageTests(base.BaseImageTests):
'--public ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
- self.assertIn("a", json_output["properties"])
- self.assertIn("c", json_output["properties"])
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
+ self.assertIn("a", output["properties"])
+ self.assertIn("c", output["properties"])
self.openstack(
'image unset ' +
@@ -143,30 +139,30 @@ class ImageTests(base.BaseImageTests):
'--property hw_rng_model ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
- self.assertNotIn("a", json_output["properties"])
- self.assertNotIn("c", json_output["properties"])
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
+ self.assertNotIn("a", output["properties"])
+ self.assertNotIn("c", output["properties"])
# Test tags
self.assertNotIn(
'01',
- json_output["tags"]
+ output["tags"]
)
self.openstack(
'image set ' +
'--tag 01 ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
self.assertIn(
'01',
- json_output["tags"]
+ output["tags"]
)
self.openstack(
@@ -174,38 +170,38 @@ class ImageTests(base.BaseImageTests):
'--tag 01 ' +
self.name
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- self.name
- ))
+ output = self.openstack(
+ 'image show ' + self.name,
+ parse_output=True,
+ )
self.assertNotIn(
'01',
- json_output["tags"]
+ output["tags"]
)
def test_image_set_rename(self):
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'image create -f json ' +
- name
- ))
- image_id = json_output["id"]
+ output = self.openstack(
+ 'image create ' + name,
+ parse_output=True,
+ )
+ image_id = output["id"]
self.assertEqual(
name,
- json_output["name"],
+ output["name"],
)
self.openstack(
'image set ' +
'--name ' + name + 'xx ' +
image_id
)
- json_output = json.loads(self.openstack(
- 'image show -f json ' +
- name + 'xx'
- ))
+ output = self.openstack(
+ 'image show ' + name + 'xx',
+ parse_output=True,
+ )
self.assertEqual(
name + 'xx',
- json_output["name"],
+ output["name"],
)
# TODO(dtroyer): This test is incomplete and doesn't properly test
@@ -213,19 +209,21 @@ class ImageTests(base.BaseImageTests):
# properly added.
def test_image_members(self):
"""Test member add, remove, accept"""
- json_output = json.loads(self.openstack(
- 'token issue -f json'
- ))
- my_project_id = json_output['project_id']
+ output = self.openstack(
+ 'token issue',
+ parse_output=True,
+ )
+ my_project_id = output['project_id']
- json_output = json.loads(self.openstack(
+ output = self.openstack(
'image show -f json ' +
- self.name
- ))
+ self.name,
+ parse_output=True,
+ )
# NOTE(dtroyer): Until OSC supports --shared flags in create and set
# we can not properly test membership. Sometimes the
# images are shared and sometimes they are not.
- if json_output["visibility"] == 'shared':
+ if output["visibility"] == 'shared':
self.openstack(
'image add project ' +
self.name + ' ' +
@@ -243,13 +241,14 @@ class ImageTests(base.BaseImageTests):
'--accept ' +
self.name
)
- json_output = json.loads(self.openstack(
+ output = self.openstack(
'image list -f json ' +
- '--shared'
- ))
+ '--shared',
+ parse_output=True,
+ )
self.assertIn(
self.name,
- [img['Name'] for img in json_output]
+ [img['Name'] for img in output]
)
self.openstack(
@@ -257,13 +256,14 @@ class ImageTests(base.BaseImageTests):
'--reject ' +
self.name
)
- json_output = json.loads(self.openstack(
+ output = self.openstack(
'image list -f json ' +
- '--shared'
- ))
+ '--shared',
+ parse_output=True,
+ )
# self.assertNotIn(
# self.name,
- # [img['Name'] for img in json_output]
+ # [img['Name'] for img in output]
# )
self.openstack(
diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py
index 2287f329..a9c5b830 100644
--- a/openstackclient/tests/functional/network/v2/common.py
+++ b/openstackclient/tests/functional/network/v2/common.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional import base
@@ -32,7 +31,10 @@ class NetworkTagTests(NetworkTests):
def test_tag_operation(self):
# Get project IDs
- cmd_output = json.loads(self.openstack('token issue -f json '))
+ cmd_output = self.openstack(
+ 'token issue ',
+ parse_output=True,
+ )
auth_project_id = cmd_output['project_id']
# Network create with no options
@@ -63,17 +65,20 @@ class NetworkTagTests(NetworkTests):
self._set_resource_and_tag_check('set', name2, '--no-tag', [])
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)))
+ cmd_output = self.openstack(
+ '{} list --long --project {}'.format(self.base_command,
+ project_id),
+ parse_output=True,
+ )
for name, tags in expected:
net = [n for n in cmd_output if n['Name'] == name][0]
self.assertEqual(set(tags), set(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)
- ))
+ return self.openstack(
+ '{} create {} {}'.format(self.base_command, args, name),
+ parse_output=True,
+ )
def _create_resource_and_tag_check(self, args, expected):
name = uuid.uuid4().hex
@@ -89,7 +94,8 @@ class NetworkTagTests(NetworkTests):
'{} {} {} {}'.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)
- ))
+ cmd_output = self.openstack(
+ '{} show {}'.format(self.base_command, name),
+ parse_output=True,
+ )
self.assertEqual(set(expected), set(cmd_output['tags']))
diff --git a/openstackclient/tests/functional/network/v2/test_address_group.py b/openstackclient/tests/functional/network/v2/test_address_group.py
index 52c628a3..17ab2362 100644
--- a/openstackclient/tests/functional/network/v2/test_address_group.py
+++ b/openstackclient/tests/functional/network/v2/test_address_group.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -30,20 +29,22 @@ class AddressGroupTests(common.NetworkTests):
def test_address_group_create_and_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address group create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'address group create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name'],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address group create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'address group create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name'],
@@ -57,10 +58,10 @@ class AddressGroupTests(common.NetworkTests):
def test_address_group_list(self):
"""Test create, list filters, delete"""
# Get project IDs
- cmd_output = json.loads(self.openstack('token issue -f json '))
+ cmd_output = self.openstack('token issue ', parse_output=True)
auth_project_id = cmd_output['project_id']
- cmd_output = json.loads(self.openstack('project list -f json '))
+ cmd_output = self.openstack('project list ', parse_output=True)
admin_project_id = None
demo_project_id = None
for p in cmd_output:
@@ -79,10 +80,11 @@ class AddressGroupTests(common.NetworkTests):
self.assertEqual(admin_project_id, auth_project_id)
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address group create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'address group create ' +
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'address group delete ' + name1)
self.assertEqual(
admin_project_id,
@@ -90,11 +92,12 @@ class AddressGroupTests(common.NetworkTests):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address group create -f json ' +
+ cmd_output = self.openstack(
+ 'address group create ' +
'--project ' + demo_project_id +
- ' ' + name2
- ))
+ ' ' + name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'address group delete ' + name2)
self.assertEqual(
demo_project_id,
@@ -102,27 +105,30 @@ class AddressGroupTests(common.NetworkTests):
)
# Test list
- cmd_output = json.loads(self.openstack(
- 'address group list -f json ',
- ))
+ cmd_output = self.openstack(
+ 'address group list ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
# Test list --project
- cmd_output = json.loads(self.openstack(
- 'address group list -f json ' +
- '--project ' + demo_project_id
- ))
+ cmd_output = self.openstack(
+ 'address group list ' +
+ '--project ' + demo_project_id,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
# Test list --name
- cmd_output = json.loads(self.openstack(
- 'address group list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'address group list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
@@ -131,12 +137,13 @@ class AddressGroupTests(common.NetworkTests):
"""Tests create options, set, unset, and show"""
name = uuid.uuid4().hex
newname = name + "_"
- cmd_output = json.loads(self.openstack(
- 'address group create -f json ' +
+ cmd_output = self.openstack(
+ 'address group create ' +
'--description aaaa ' +
'--address 10.0.0.1 --address 2001::/16 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'address group delete ' + newname)
self.assertEqual(name, cmd_output['name'])
self.assertEqual('aaaa', cmd_output['description'])
@@ -153,10 +160,11 @@ class AddressGroupTests(common.NetworkTests):
self.assertOutput('', raw_output)
# Show the updated address group
- cmd_output = json.loads(self.openstack(
- 'address group show -f json ' +
+ cmd_output = self.openstack(
+ 'address group show ' +
newname,
- ))
+ parse_output=True,
+ )
self.assertEqual(newname, cmd_output['name'])
self.assertEqual('bbbb', cmd_output['description'])
self.assertEqual(4, len(cmd_output['addresses']))
@@ -170,8 +178,9 @@ class AddressGroupTests(common.NetworkTests):
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'address group show -f json ' +
+ cmd_output = self.openstack(
+ 'address group show ' +
newname,
- ))
+ parse_output=True,
+ )
self.assertEqual(0, len(cmd_output['addresses']))
diff --git a/openstackclient/tests/functional/network/v2/test_address_scope.py b/openstackclient/tests/functional/network/v2/test_address_scope.py
index 8a99ec5e..8ebb9522 100644
--- a/openstackclient/tests/functional/network/v2/test_address_scope.py
+++ b/openstackclient/tests/functional/network/v2/test_address_scope.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -33,10 +32,11 @@ class AddressScopeTests(common.NetworkTests):
def test_address_scope_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address scope create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'address scope create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name'],
@@ -45,10 +45,11 @@ class AddressScopeTests(common.NetworkTests):
self.assertFalse(cmd_output['shared'])
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address scope create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'address scope create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name'],
@@ -62,12 +63,13 @@ class AddressScopeTests(common.NetworkTests):
def test_address_scope_list(self):
"""Test create defaults, list filters, delete"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address scope create -f json ' +
+ cmd_output = self.openstack(
+ 'address scope create ' +
'--ip-version 4 ' +
'--share ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'address scope delete ' + name1)
self.assertEqual(
name1,
@@ -80,12 +82,13 @@ class AddressScopeTests(common.NetworkTests):
self.assertTrue(cmd_output['shared'])
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'address scope create -f json ' +
+ cmd_output = self.openstack(
+ 'address scope create ' +
'--ip-version 6 ' +
'--no-share ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'address scope delete ' + name2)
self.assertEqual(
name2,
@@ -98,25 +101,28 @@ class AddressScopeTests(common.NetworkTests):
self.assertFalse(cmd_output['shared'])
# Test list
- cmd_output = json.loads(self.openstack(
- 'address scope list -f json ',
- ))
+ cmd_output = self.openstack(
+ 'address scope list ',
+ parse_output=True,
+ )
col_data = [x["IP Version"] for x in cmd_output]
self.assertIn(4, col_data)
self.assertIn(6, col_data)
# Test list --share
- cmd_output = json.loads(self.openstack(
- 'address scope list -f json --share',
- ))
+ cmd_output = self.openstack(
+ 'address scope list --share',
+ parse_output=True,
+ )
col_data = [x["Shared"] for x in cmd_output]
self.assertIn(True, col_data)
self.assertNotIn(False, col_data)
# Test list --no-share
- cmd_output = json.loads(self.openstack(
- 'address scope list -f json --no-share',
- ))
+ cmd_output = self.openstack(
+ 'address scope list --no-share',
+ parse_output=True,
+ )
col_data = [x["Shared"] for x in cmd_output]
self.assertIn(False, col_data)
self.assertNotIn(True, col_data)
@@ -125,12 +131,13 @@ class AddressScopeTests(common.NetworkTests):
"""Tests create options, set, show, delete"""
name = uuid.uuid4().hex
newname = name + "_"
- cmd_output = json.loads(self.openstack(
- 'address scope create -f json ' +
+ cmd_output = self.openstack(
+ 'address scope create ' +
'--ip-version 4 ' +
'--no-share ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'address scope delete ' + newname)
self.assertEqual(
name,
@@ -150,10 +157,11 @@ class AddressScopeTests(common.NetworkTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'address scope show -f json ' +
+ cmd_output = self.openstack(
+ 'address scope show ' +
newname,
- ))
+ parse_output=True,
+ )
self.assertEqual(
newname,
cmd_output['name'],
diff --git a/openstackclient/tests/functional/network/v2/test_floating_ip.py b/openstackclient/tests/functional/network/v2/test_floating_ip.py
index 9d109f87..871cab2d 100644
--- a/openstackclient/tests/functional/network/v2/test_floating_ip.py
+++ b/openstackclient/tests/functional/network/v2/test_floating_ip.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import random
import uuid
@@ -29,18 +28,20 @@ class FloatingIpTests(common.NetworkTests):
cls.PRIVATE_NETWORK_NAME = uuid.uuid4().hex
# Create a network for the floating ip
- json_output = json.loads(cls.openstack(
- 'network create -f json ' +
+ json_output = cls.openstack(
+ 'network create ' +
'--external ' +
- cls.EXTERNAL_NETWORK_NAME
- ))
+ cls.EXTERNAL_NETWORK_NAME,
+ parse_output=True,
+ )
cls.external_network_id = json_output["id"]
# Create a private network for the port
- json_output = json.loads(cls.openstack(
- 'network create -f json ' +
- cls.PRIVATE_NETWORK_NAME
- ))
+ json_output = cls.openstack(
+ 'network create ' +
+ cls.PRIVATE_NETWORK_NAME,
+ parse_output=True,
+ )
cls.private_network_id = json_output["id"]
@classmethod
@@ -81,12 +82,13 @@ class FloatingIpTests(common.NetworkTests):
)) + ".0/26"
try:
# Create a subnet for the network
- json_output = json.loads(self.openstack(
- 'subnet create -f json ' +
+ json_output = self.openstack(
+ 'subnet create ' +
'--network ' + network_name + ' ' +
'--subnet-range ' + subnet + ' ' +
- subnet_name
- ))
+ subnet_name,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
subnet_id = json_output["id"]
except Exception:
@@ -109,11 +111,12 @@ class FloatingIpTests(common.NetworkTests):
)
self.addCleanup(self.openstack, 'subnet delete ' + ext_subnet_id)
- json_output = json.loads(self.openstack(
- 'floating ip create -f json ' +
+ json_output = self.openstack(
+ 'floating ip create ' +
'--description aaaa ' +
- self.EXTERNAL_NETWORK_NAME
- ))
+ self.EXTERNAL_NETWORK_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
ip1 = json_output["id"]
self.assertEqual(
@@ -121,11 +124,12 @@ class FloatingIpTests(common.NetworkTests):
json_output["description"],
)
- json_output = json.loads(self.openstack(
- 'floating ip create -f json ' +
+ json_output = self.openstack(
+ 'floating ip create ' +
'--description bbbb ' +
- self.EXTERNAL_NETWORK_NAME
- ))
+ self.EXTERNAL_NETWORK_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
ip2 = json_output["id"]
self.assertEqual(
@@ -149,11 +153,12 @@ class FloatingIpTests(common.NetworkTests):
)
self.addCleanup(self.openstack, 'subnet delete ' + ext_subnet_id)
- json_output = json.loads(self.openstack(
- 'floating ip create -f json ' +
+ json_output = self.openstack(
+ 'floating ip create ' +
'--description aaaa ' +
- self.EXTERNAL_NETWORK_NAME
- ))
+ self.EXTERNAL_NETWORK_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
ip1 = json_output["id"]
self.addCleanup(self.openstack, 'floating ip delete ' + ip1)
@@ -164,11 +169,12 @@ class FloatingIpTests(common.NetworkTests):
self.assertIsNotNone(json_output["floating_network_id"])
fip1 = json_output["floating_ip_address"]
- json_output = json.loads(self.openstack(
- 'floating ip create -f json ' +
+ json_output = self.openstack(
+ 'floating ip create ' +
'--description bbbb ' +
- self.EXTERNAL_NETWORK_NAME
- ))
+ self.EXTERNAL_NETWORK_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
ip2 = json_output["id"]
self.addCleanup(self.openstack, 'floating ip delete ' + ip2)
@@ -180,9 +186,10 @@ class FloatingIpTests(common.NetworkTests):
fip2 = json_output["floating_ip_address"]
# Test list
- json_output = json.loads(self.openstack(
- 'floating ip list -f json'
- ))
+ json_output = self.openstack(
+ 'floating ip list',
+ parse_output=True,
+ )
fip_map = {
item.get('ID'):
item.get('Floating IP Address') for item in json_output
@@ -194,10 +201,11 @@ class FloatingIpTests(common.NetworkTests):
self.assertIn(fip2, fip_map.values())
# Test list --long
- json_output = json.loads(self.openstack(
- 'floating ip list -f json ' +
- '--long'
- ))
+ json_output = self.openstack(
+ 'floating ip list ' +
+ '--long',
+ parse_output=True,
+ )
fip_map = {
item.get('ID'):
item.get('Floating IP Address') for item in json_output
@@ -214,10 +222,11 @@ class FloatingIpTests(common.NetworkTests):
# TODO(dtroyer): add more filter tests
- json_output = json.loads(self.openstack(
- 'floating ip show -f json ' +
- ip1
- ))
+ json_output = self.openstack(
+ 'floating ip show ' +
+ ip1,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
self.assertEqual(
ip1,
@@ -251,11 +260,12 @@ class FloatingIpTests(common.NetworkTests):
self.ROUTER = uuid.uuid4().hex
self.PORT_NAME = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'floating ip create -f json ' +
+ json_output = self.openstack(
+ 'floating ip create ' +
'--description aaaa ' +
- self.EXTERNAL_NETWORK_NAME
- ))
+ self.EXTERNAL_NETWORK_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
ip1 = json_output["id"]
self.addCleanup(self.openstack, 'floating ip delete ' + ip1)
@@ -264,19 +274,21 @@ class FloatingIpTests(common.NetworkTests):
json_output["description"],
)
- json_output = json.loads(self.openstack(
- 'port create -f json ' +
+ json_output = self.openstack(
+ 'port create ' +
'--network ' + self.PRIVATE_NETWORK_NAME + ' ' +
'--fixed-ip subnet=' + priv_subnet_id + ' ' +
- self.PORT_NAME
- ))
+ self.PORT_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
port_id = json_output["id"]
- json_output = json.loads(self.openstack(
- 'router create -f json ' +
- self.ROUTER
- ))
+ json_output = self.openstack(
+ 'router create ' +
+ self.ROUTER,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output["id"])
self.addCleanup(self.openstack, 'router delete ' + self.ROUTER)
@@ -310,10 +322,11 @@ class FloatingIpTests(common.NetworkTests):
'floating ip unset --port ' + ip1,
)
- json_output = json.loads(self.openstack(
- 'floating ip show -f json ' +
- ip1
- ))
+ json_output = self.openstack(
+ 'floating ip show ' +
+ ip1,
+ parse_output=True,
+ )
self.assertEqual(
port_id,
diff --git a/openstackclient/tests/functional/network/v2/test_ip_availability.py b/openstackclient/tests/functional/network/v2/test_ip_availability.py
index 86a53c0c..6697ed36 100644
--- a/openstackclient/tests/functional/network/v2/test_ip_availability.py
+++ b/openstackclient/tests/functional/network/v2/test_ip_availability.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -31,12 +30,13 @@ class IPAvailabilityTests(common.NetworkTests):
'network create ' +
cls.NETWORK_NAME
)
- cmd_output = json.loads(cls.openstack(
- 'subnet create -f json ' +
+ cmd_output = cls.openstack(
+ 'subnet create ' +
'--network ' + cls.NETWORK_NAME + ' ' +
'--subnet-range 10.10.10.0/24 ' +
- cls.NAME
- ))
+ cls.NAME,
+ parse_output=True,
+ )
cls.assertOutput(cls.NAME, cmd_output['name'])
@classmethod
@@ -64,15 +64,17 @@ class IPAvailabilityTests(common.NetworkTests):
def test_ip_availability_list(self):
"""Test ip availability list"""
- cmd_output = json.loads(self.openstack(
- 'ip availability list -f json'))
+ cmd_output = self.openstack(
+ 'ip availability list',
+ parse_output=True,)
names = [x['Network Name'] for x in cmd_output]
self.assertIn(self.NETWORK_NAME, names)
def test_ip_availability_show(self):
"""Test ip availability show"""
- cmd_output = json.loads(self.openstack(
- 'ip availability show -f json ' + self.NETWORK_NAME))
+ cmd_output = self.openstack(
+ 'ip availability show ' + self.NETWORK_NAME,
+ parse_output=True,)
self.assertEqual(
self.NETWORK_NAME,
cmd_output['network_name'],
diff --git a/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py b/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py
index bbb9a7cd..2563bcf9 100644
--- a/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py
+++ b/openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py
@@ -11,8 +11,6 @@
# under the License.
#
-
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -32,9 +30,10 @@ class L3ConntrackHelperTests(common.NetworkTests):
def _create_router(self):
router_name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'router create -f json ' + router_name
- ))
+ json_output = self.openstack(
+ 'router create ' + router_name,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
router_id = json_output['id']
self.addCleanup(self.openstack, 'router delete ' + router_id)
@@ -43,13 +42,17 @@ class L3ConntrackHelperTests(common.NetworkTests):
def _create_helpers(self, router_id, helpers):
created_helpers = []
for helper in helpers:
- output = json.loads(self.openstack(
+ output = self.openstack(
'network l3 conntrack helper create %(router)s '
- '--helper %(helper)s --protocol %(protocol)s --port %(port)s '
- '-f json' % {'router': router_id,
- 'helper': helper['helper'],
- 'protocol': helper['protocol'],
- 'port': helper['port']}))
+ '--helper %(helper)s --protocol %(protocol)s '
+ '--port %(port)s ' % {
+ 'router': router_id,
+ 'helper': helper['helper'],
+ 'protocol': helper['protocol'],
+ 'port': helper['port'],
+ },
+ parse_output=True,
+ )
self.assertEqual(helper['helper'], output['helper'])
self.assertEqual(helper['protocol'], output['protocol'])
self.assertEqual(helper['port'], output['port'])
@@ -105,9 +108,10 @@ class L3ConntrackHelperTests(common.NetworkTests):
]
router_id = self._create_router()
self._create_helpers(router_id, helpers)
- output = json.loads(self.openstack(
- 'network l3 conntrack helper list %s -f json ' % router_id
- ))
+ output = self.openstack(
+ 'network l3 conntrack helper list %s ' % router_id,
+ parse_output=True,
+ )
for ct in output:
self.assertEqual(router_id, ct.pop('Router ID'))
ct.pop("ID")
@@ -120,10 +124,14 @@ class L3ConntrackHelperTests(common.NetworkTests):
'port': 69}
router_id = self._create_router()
created_helper = self._create_helpers(router_id, [helper])[0]
- output = json.loads(self.openstack(
+ output = self.openstack(
'network l3 conntrack helper show %(router_id)s %(ct_id)s '
'-f json' % {
- 'router_id': router_id, 'ct_id': created_helper['id']}))
+ 'router_id': router_id,
+ 'ct_id': created_helper['id'],
+ },
+ parse_output=True,
+ )
self.assertEqual(helper['helper'], output['helper'])
self.assertEqual(helper['protocol'], output['protocol'])
self.assertEqual(helper['port'], output['port'])
@@ -136,10 +144,14 @@ class L3ConntrackHelperTests(common.NetworkTests):
'port': helper['port'] + 1})
self.assertOutput('', raw_output)
- output = json.loads(self.openstack(
+ output = self.openstack(
'network l3 conntrack helper show %(router_id)s %(ct_id)s '
'-f json' % {
- 'router_id': router_id, 'ct_id': created_helper['id']}))
+ 'router_id': router_id,
+ 'ct_id': created_helper['id'],
+ },
+ parse_output=True,
+ )
self.assertEqual(helper['port'] + 1, output['port'])
self.assertEqual(helper['helper'], output['helper'])
self.assertEqual(helper['protocol'], output['protocol'])
diff --git a/openstackclient/tests/functional/network/v2/test_local_ip.py b/openstackclient/tests/functional/network/v2/test_local_ip.py
index dd278e38..b5672b6d 100644
--- a/openstackclient/tests/functional/network/v2/test_local_ip.py
+++ b/openstackclient/tests/functional/network/v2/test_local_ip.py
@@ -11,9 +11,7 @@
# 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 json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -33,20 +31,22 @@ class LocalIPTests(common.NetworkTests):
def test_local_ip_create_and_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'local ip create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'local ip create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name'],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'local ip create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'local ip create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name'],
@@ -60,10 +60,10 @@ class LocalIPTests(common.NetworkTests):
def test_local_ip_list(self):
"""Test create, list filters, delete"""
# Get project IDs
- cmd_output = json.loads(self.openstack('token issue -f json '))
+ cmd_output = self.openstack('token issue ', parse_output=True)
auth_project_id = cmd_output['project_id']
- cmd_output = json.loads(self.openstack('project list -f json '))
+ cmd_output = self.openstack('project list ', parse_output=True)
admin_project_id = None
demo_project_id = None
for p in cmd_output:
@@ -82,10 +82,11 @@ class LocalIPTests(common.NetworkTests):
self.assertEqual(admin_project_id, auth_project_id)
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'local ip create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'local ip create ' +
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'local ip delete ' + name1)
self.assertEqual(
admin_project_id,
@@ -93,11 +94,12 @@ class LocalIPTests(common.NetworkTests):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'local ip create -f json ' +
+ cmd_output = self.openstack(
+ 'local ip create ' +
'--project ' + demo_project_id +
- ' ' + name2
- ))
+ ' ' + name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'local ip delete ' + name2)
self.assertEqual(
demo_project_id,
@@ -105,27 +107,30 @@ class LocalIPTests(common.NetworkTests):
)
# Test list
- cmd_output = json.loads(self.openstack(
- 'local ip list -f json ',
- ))
+ cmd_output = self.openstack(
+ 'local ip list ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
# Test list --project
- cmd_output = json.loads(self.openstack(
- 'local ip list -f json ' +
- '--project ' + demo_project_id
- ))
+ cmd_output = self.openstack(
+ 'local ip list ' +
+ '--project ' + demo_project_id,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
# Test list --name
- cmd_output = json.loads(self.openstack(
- 'local ip list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'local ip list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
@@ -134,11 +139,12 @@ class LocalIPTests(common.NetworkTests):
"""Tests create options, set, and show"""
name = uuid.uuid4().hex
newname = name + "_"
- cmd_output = json.loads(self.openstack(
- 'local ip create -f json ' +
+ cmd_output = self.openstack(
+ 'local ip create ' +
'--description aaaa ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'local ip delete ' + newname)
self.assertEqual(name, cmd_output['name'])
self.assertEqual('aaaa', cmd_output['description'])
@@ -153,9 +159,10 @@ class LocalIPTests(common.NetworkTests):
self.assertOutput('', raw_output)
# Show the updated local ip
- cmd_output = json.loads(self.openstack(
- 'local ip show -f json ' +
+ cmd_output = self.openstack(
+ 'local ip show ' +
newname,
- ))
+ parse_output=True,
+ )
self.assertEqual(newname, cmd_output['name'])
self.assertEqual('bbbb', cmd_output['description'])
diff --git a/openstackclient/tests/functional/network/v2/test_network.py b/openstackclient/tests/functional/network/v2/test_network.py
index f68b3143..20be2d1a 100644
--- a/openstackclient/tests/functional/network/v2/test_network.py
+++ b/openstackclient/tests/functional/network/v2/test_network.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -34,11 +33,12 @@ class NetworkTests(common.NetworkTagTests):
# Network create with minimum options
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--subnet 1.2.3.4/28 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete ' + name1)
self.assertIsNotNone(cmd_output["id"])
@@ -53,12 +53,13 @@ class NetworkTests(common.NetworkTagTests):
# Network create with more options
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--subnet 1.2.4.4/28 ' +
'--share ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete ' + name2)
self.assertIsNotNone(cmd_output["id"])
@@ -80,10 +81,10 @@ class NetworkTests(common.NetworkTagTests):
self.skipTest("No Network service present")
# Get project IDs
- cmd_output = json.loads(self.openstack('token issue -f json '))
+ cmd_output = self.openstack('token issue ', parse_output=True)
auth_project_id = cmd_output['project_id']
- cmd_output = json.loads(self.openstack('project list -f json '))
+ cmd_output = self.openstack('project list ', parse_output=True)
admin_project_id = None
demo_project_id = None
for p in cmd_output:
@@ -103,10 +104,11 @@ class NetworkTests(common.NetworkTagTests):
# Network create with no options
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'network create ' +
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete ' + name1)
self.assertIsNotNone(cmd_output["id"])
@@ -133,11 +135,12 @@ class NetworkTests(common.NetworkTagTests):
# Network create with options
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--project demo ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete ' + name2)
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
@@ -155,11 +158,12 @@ class NetworkTests(common.NetworkTagTests):
self.skipTest("Skip Nova-net test")
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--subnet 9.8.7.6/28 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
name1,
@@ -167,11 +171,12 @@ class NetworkTests(common.NetworkTagTests):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--subnet 8.7.6.5/28 ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
name2,
@@ -184,11 +189,12 @@ class NetworkTests(common.NetworkTagTests):
self.skipTest("No Network service present")
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--description aaaa ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
'aaaa',
@@ -196,11 +202,12 @@ class NetworkTests(common.NetworkTagTests):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
'--description bbbb ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
'bbbb',
@@ -217,11 +224,12 @@ class NetworkTests(common.NetworkTagTests):
network_options = '--description aaaa --no-default '
else:
network_options = '--subnet 3.4.5.6/28 '
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' +
+ cmd_output = self.openstack(
+ 'network create ' +
network_options +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete %s' % name1)
self.assertIsNotNone(cmd_output["id"])
if self.haz_network:
@@ -254,10 +262,11 @@ class NetworkTests(common.NetworkTagTests):
network_options = '--description bbbb --disable '
else:
network_options = '--subnet 4.5.6.7/28 '
- cmd_output = json.loads(self.openstack(
- 'network create -f json --share %s%s' %
- (network_options, name2)
- ))
+ cmd_output = self.openstack(
+ 'network create --share %s%s' %
+ (network_options, name2),
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete ' + name2)
self.assertIsNotNone(cmd_output["id"])
if self.haz_network:
@@ -280,54 +289,60 @@ class NetworkTests(common.NetworkTagTests):
self.assertTrue(cmd_output["share_address"])
# Test list
- cmd_output = json.loads(self.openstack(
- "network list -f json "
- ))
+ cmd_output = self.openstack(
+ "network list ",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertIn(name2, col_name)
# Test list --long
if self.haz_network:
- cmd_output = json.loads(self.openstack(
- "network list -f json --long"
- ))
+ cmd_output = self.openstack(
+ "network list --long",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertIn(name2, col_name)
# Test list --long --enable
if self.haz_network:
- cmd_output = json.loads(self.openstack(
- "network list -f json --enable --long"
- ))
+ cmd_output = self.openstack(
+ "network list --enable --long",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertNotIn(name2, col_name)
# Test list --long --disable
if self.haz_network:
- cmd_output = json.loads(self.openstack(
- "network list -f json --disable --long"
- ))
+ cmd_output = self.openstack(
+ "network list --disable --long",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, col_name)
self.assertIn(name2, col_name)
# Test list --share
if self.haz_network:
- cmd_output = json.loads(self.openstack(
- "network list -f json --share "
- ))
+ cmd_output = self.openstack(
+ "network list --share ",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, col_name)
self.assertIn(name2, col_name)
# Test list --no-share
if self.haz_network:
- cmd_output = json.loads(self.openstack(
- "network list -f json --no-share "
- ))
+ cmd_output = self.openstack(
+ "network list --no-share ",
+ parse_output=True,
+ )
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.assertNotIn(name2, col_name)
@@ -339,9 +354,10 @@ class NetworkTests(common.NetworkTagTests):
self.skipTest("No dhcp_agent_scheduler extension present")
name1 = uuid.uuid4().hex
- cmd_output1 = json.loads(self.openstack(
- 'network create -f json --description aaaa %s' % name1
- ))
+ cmd_output1 = self.openstack(
+ 'network create --description aaaa %s' % name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete %s' % name1)
@@ -349,9 +365,10 @@ class NetworkTests(common.NetworkTagTests):
network_id = cmd_output1['id']
# Get DHCP Agent ID
- cmd_output2 = json.loads(self.openstack(
- 'network agent list -f json --agent-type dhcp'
- ))
+ cmd_output2 = self.openstack(
+ 'network agent list --agent-type dhcp',
+ parse_output=True,
+ )
agent_id = cmd_output2[0]['ID']
# Add Agent to Network
@@ -360,9 +377,10 @@ class NetworkTests(common.NetworkTagTests):
)
# Test network list --agent
- cmd_output3 = json.loads(self.openstack(
- 'network list -f json --agent %s' % agent_id
- ))
+ cmd_output3 = self.openstack(
+ 'network list --agent %s' % agent_id,
+ parse_output=True,
+ )
# Cleanup
# Remove Agent from Network
@@ -383,16 +401,17 @@ class NetworkTests(common.NetworkTagTests):
self.skipTest("No Network service present")
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json '
+ cmd_output = self.openstack(
+ 'network create '
'--description aaaa '
'--enable '
'--no-share '
'--internal '
'--no-default '
'--enable-port-security %s' %
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete %s' % name)
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
@@ -425,9 +444,10 @@ class NetworkTests(common.NetworkTagTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'network show -f json ' + name
- ))
+ cmd_output = self.openstack(
+ 'network show ' + name,
+ parse_output=True,
+ )
self.assertEqual(
'cccc',
diff --git a/openstackclient/tests/functional/network/v2/test_network_agent.py b/openstackclient/tests/functional/network/v2/test_network_agent.py
index e5580945..d3e6353e 100644
--- a/openstackclient/tests/functional/network/v2/test_network_agent.py
+++ b/openstackclient/tests/functional/network/v2/test_network_agent.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -33,17 +32,19 @@ class NetworkAgentTests(common.NetworkTests):
"""
# agent list
- agent_list = json.loads(self.openstack(
- 'network agent list -f json'
- ))
+ agent_list = self.openstack(
+ 'network agent list',
+ parse_output=True,
+ )
self.assertIsNotNone(agent_list[0])
agent_ids = list([row["ID"] for row in agent_list])
# agent show
- cmd_output = json.loads(self.openstack(
- 'network agent show -f json %s' % agent_ids[0]
- ))
+ cmd_output = self.openstack(
+ 'network agent show %s' % agent_ids[0],
+ parse_output=True,
+ )
self.assertEqual(
agent_ids[0],
cmd_output['id'],
@@ -60,9 +61,10 @@ class NetworkAgentTests(common.NetworkTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'network agent show -f json %s' % agent_ids[0]
- ))
+ cmd_output = self.openstack(
+ 'network agent show %s' % agent_ids[0],
+ parse_output=True,
+ )
self.assertEqual(
False,
cmd_output['admin_state_up'],
@@ -73,9 +75,10 @@ class NetworkAgentTests(common.NetworkTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'network agent show -f json %s' % agent_ids[0]
- ))
+ cmd_output = self.openstack(
+ 'network agent show %s' % agent_ids[0],
+ parse_output=True,
+ )
self.assertEqual(
True,
cmd_output['admin_state_up'],
@@ -98,9 +101,10 @@ class NetworkAgentListTests(common.NetworkTests):
self.skipTest("No dhcp_agent_scheduler extension present")
name1 = uuid.uuid4().hex
- cmd_output1 = json.loads(self.openstack(
- 'network create -f json --description aaaa %s' % name1
- ))
+ cmd_output1 = self.openstack(
+ 'network create --description aaaa %s' % name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network delete %s' % name1)
@@ -108,9 +112,10 @@ class NetworkAgentListTests(common.NetworkTests):
network_id = cmd_output1['id']
# Get DHCP Agent ID
- cmd_output2 = json.loads(self.openstack(
- 'network agent list -f json --agent-type dhcp'
- ))
+ cmd_output2 = self.openstack(
+ 'network agent list --agent-type dhcp',
+ parse_output=True,
+ )
agent_id = cmd_output2[0]['ID']
# Add Agent to Network
@@ -120,9 +125,10 @@ class NetworkAgentListTests(common.NetworkTests):
)
# Test network agent list --network
- cmd_output3 = json.loads(self.openstack(
- 'network agent list -f json --network %s' % network_id
- ))
+ cmd_output3 = self.openstack(
+ 'network agent list --network %s' % network_id,
+ parse_output=True,
+ )
# Cleanup
# Remove Agent from Network
@@ -144,15 +150,17 @@ class NetworkAgentListTests(common.NetworkTests):
self.skipTest("No l3_agent_scheduler extension present")
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'router create -f json %s' % name))
+ cmd_output = self.openstack(
+ 'router create %s' % name,
+ parse_output=True,)
self.addCleanup(self.openstack, 'router delete %s' % name)
# Get router ID
router_id = cmd_output['id']
# Get l3 agent id
- cmd_output = json.loads(self.openstack(
- 'network agent list -f json --agent-type l3'))
+ cmd_output = self.openstack(
+ 'network agent list --agent-type l3',
+ parse_output=True,)
# Check at least one L3 agent is included in the response.
self.assertTrue(cmd_output)
@@ -163,8 +171,9 @@ class NetworkAgentListTests(common.NetworkTests):
'network agent add router --l3 %s %s' % (agent_id, router_id))
# Test router list --agent
- cmd_output = json.loads(self.openstack(
- 'network agent list -f json --router %s' % router_id))
+ cmd_output = self.openstack(
+ 'network agent list --router %s' % router_id,
+ parse_output=True,)
agent_ids = [x['ID'] for x in cmd_output]
self.assertIn(agent_id, agent_ids)
@@ -172,7 +181,8 @@ class NetworkAgentListTests(common.NetworkTests):
# Remove router from agent
self.openstack(
'network agent remove router --l3 %s %s' % (agent_id, router_id))
- cmd_output = json.loads(self.openstack(
- 'network agent list -f json --router %s' % router_id))
+ cmd_output = self.openstack(
+ 'network agent list --router %s' % router_id,
+ parse_output=True,)
agent_ids = [x['ID'] for x in cmd_output]
self.assertNotIn(agent_id, agent_ids)
diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor.py b/openstackclient/tests/functional/network/v2/test_network_flavor.py
index cf68a096..2ac0daef 100644
--- a/openstackclient/tests/functional/network/v2/test_network_flavor.py
+++ b/openstackclient/tests/functional/network/v2/test_network_flavor.py
@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -30,17 +28,19 @@ class NetworkFlavorTests(common.NetworkTests):
"""Test add and remove network flavor to/from profile"""
# Create Flavor
name1 = uuid.uuid4().hex
- cmd_output1 = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription '
+ cmd_output1 = self.openstack(
+ 'network flavor create --description testdescription '
'--enable --service-type L3_ROUTER_NAT ' + name1,
- ))
+ parse_output=True,
+ )
flavor_id = cmd_output1.get('id')
# Create Service Flavor
- cmd_output2 = json.loads(self.openstack(
- 'network flavor profile create -f json --description '
- 'fakedescription --enable --metainfo Extrainfo'
- ))
+ cmd_output2 = self.openstack(
+ 'network flavor profile create --description '
+ 'fakedescription --enable --metainfo Extrainfo',
+ parse_output=True,
+ )
service_profile_id = cmd_output2.get('id')
self.addCleanup(self.openstack, 'network flavor delete %s' %
@@ -53,9 +53,10 @@ class NetworkFlavorTests(common.NetworkTests):
flavor_id + ' ' + service_profile_id
)
- cmd_output4 = json.loads(self.openstack(
- 'network flavor show -f json ' + flavor_id
- ))
+ cmd_output4 = self.openstack(
+ 'network flavor show ' + flavor_id,
+ parse_output=True,
+ )
service_profile_ids1 = cmd_output4.get('service_profile_ids')
# Assert
@@ -68,9 +69,10 @@ class NetworkFlavorTests(common.NetworkTests):
flavor_id + ' ' + service_profile_id
)
- cmd_output6 = json.loads(self.openstack(
- 'network flavor show -f json ' + flavor_id
- ))
+ cmd_output6 = self.openstack(
+ 'network flavor show ' + flavor_id,
+ parse_output=True,
+ )
service_profile_ids2 = cmd_output6.get('service_profile_ids')
# Assert
@@ -79,10 +81,11 @@ class NetworkFlavorTests(common.NetworkTests):
def test_network_flavor_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription '
+ cmd_output = self.openstack(
+ 'network flavor create --description testdescription '
'--enable --service-type L3_ROUTER_NAT ' + name1,
- ))
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name'],
@@ -94,10 +97,11 @@ class NetworkFlavorTests(common.NetworkTests):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription1 '
+ cmd_output = self.openstack(
+ 'network flavor create --description testdescription1 '
'--disable --service-type L3_ROUTER_NAT ' + name2,
- ))
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name'],
@@ -114,10 +118,11 @@ class NetworkFlavorTests(common.NetworkTests):
def test_network_flavor_list(self):
"""Test create defaults, list filters, delete"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription '
+ cmd_output = self.openstack(
+ 'network flavor create --description testdescription '
'--enable --service-type L3_ROUTER_NAT ' + name1,
- ))
+ parse_output=True,
+ )
self.addCleanup(self.openstack, "network flavor delete " + name1)
self.assertEqual(
name1,
@@ -133,10 +138,11 @@ class NetworkFlavorTests(common.NetworkTests):
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription1 '
+ cmd_output = self.openstack(
+ 'network flavor create --description testdescription1 '
'--disable --service-type L3_ROUTER_NAT ' + name2,
- ))
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name'],
@@ -152,8 +158,9 @@ class NetworkFlavorTests(common.NetworkTests):
self.addCleanup(self.openstack, "network flavor delete " + name2)
# Test list
- cmd_output = json.loads(self.openstack(
- 'network flavor list -f json ',))
+ cmd_output = self.openstack(
+ 'network flavor list ',
+ parse_output=True,)
self.assertIsNotNone(cmd_output)
name_list = [item.get('Name') for item in cmd_output]
@@ -164,10 +171,11 @@ class NetworkFlavorTests(common.NetworkTests):
"""Tests create options, set, show, delete"""
name = uuid.uuid4().hex
newname = name + "_"
- cmd_output = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription '
+ cmd_output = self.openstack(
+ 'network flavor create --description testdescription '
'--disable --service-type L3_ROUTER_NAT ' + name,
- ))
+ parse_output=True,
+ )
self.addCleanup(self.openstack, "network flavor delete " + newname)
self.assertEqual(
name,
@@ -187,8 +195,9 @@ class NetworkFlavorTests(common.NetworkTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'network flavor show -f json ' + newname,))
+ cmd_output = self.openstack(
+ 'network flavor show ' + newname,
+ parse_output=True,)
self.assertEqual(
newname,
cmd_output['name'],
@@ -205,13 +214,15 @@ class NetworkFlavorTests(common.NetworkTests):
def test_network_flavor_show(self):
"""Test show network flavor"""
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network flavor create -f json --description testdescription '
+ cmd_output = self.openstack(
+ 'network flavor create --description testdescription '
'--disable --service-type L3_ROUTER_NAT ' + name,
- ))
+ parse_output=True,
+ )
self.addCleanup(self.openstack, "network flavor delete " + name)
- cmd_output = json.loads(self.openstack(
- 'network flavor show -f json ' + name,))
+ cmd_output = self.openstack(
+ 'network flavor show ' + name,
+ parse_output=True,)
self.assertEqual(
name,
cmd_output['name'],
diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py b/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py
index 5b5ec926..60fd949b 100644
--- a/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py
+++ b/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py
@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from openstackclient.tests.functional.network.v2 import common
@@ -28,11 +26,12 @@ class NetworkFlavorProfileTests(common.NetworkTests):
self.skipTest("No Network service present")
def test_network_flavor_profile_create(self):
- json_output = json.loads(self.openstack(
- 'network flavor profile create -f json ' +
+ json_output = self.openstack(
+ 'network flavor profile create ' +
'--description ' + self.DESCRIPTION + ' ' +
- '--enable --metainfo ' + self.METAINFO
- ))
+ '--enable --metainfo ' + self.METAINFO,
+ parse_output=True,
+ )
ID = json_output.get('id')
self.assertIsNotNone(ID)
self.assertTrue(json_output.get('enabled'))
@@ -50,12 +49,13 @@ class NetworkFlavorProfileTests(common.NetworkTests):
self.assertOutput('', raw_output)
def test_network_flavor_profile_list(self):
- json_output = json.loads(self.openstack(
- 'network flavor profile create -f json ' +
+ json_output = self.openstack(
+ 'network flavor profile create ' +
'--description ' + self.DESCRIPTION + ' ' +
'--enable ' +
- '--metainfo ' + self.METAINFO
- ))
+ '--metainfo ' + self.METAINFO,
+ parse_output=True,
+ )
ID1 = json_output.get('id')
self.assertIsNotNone(ID1)
self.assertTrue(json_output.get('enabled'))
@@ -68,12 +68,13 @@ class NetworkFlavorProfileTests(common.NetworkTests):
json_output.get('meta_info'),
)
- json_output = json.loads(self.openstack(
- 'network flavor profile create -f json ' +
+ json_output = self.openstack(
+ 'network flavor profile create ' +
'--description ' + self.DESCRIPTION + ' ' +
'--disable ' +
- '--metainfo ' + self.METAINFO
- ))
+ '--metainfo ' + self.METAINFO,
+ parse_output=True,
+ )
ID2 = json_output.get('id')
self.assertIsNotNone(ID2)
self.assertFalse(json_output.get('enabled'))
@@ -87,9 +88,10 @@ class NetworkFlavorProfileTests(common.NetworkTests):
)
# Test list
- json_output = json.loads(self.openstack(
- 'network flavor profile list -f json'
- ))
+ json_output = self.openstack(
+ 'network flavor profile list',
+ parse_output=True,
+ )
self.assertIsNotNone(json_output)
id_list = [item.get('ID') for item in json_output]
@@ -103,12 +105,13 @@ class NetworkFlavorProfileTests(common.NetworkTests):
self.assertOutput('', raw_output)
def test_network_flavor_profile_set(self):
- json_output_1 = json.loads(self.openstack(
- 'network flavor profile create -f json ' +
+ json_output_1 = self.openstack(
+ 'network flavor profile create ' +
'--description ' + self.DESCRIPTION + ' ' +
'--enable ' +
- '--metainfo ' + self.METAINFO
- ))
+ '--metainfo ' + self.METAINFO,
+ parse_output=True,
+ )
ID = json_output_1.get('id')
self.assertIsNotNone(ID)
self.assertTrue(json_output_1.get('enabled'))
@@ -123,9 +126,10 @@ class NetworkFlavorProfileTests(common.NetworkTests):
self.openstack('network flavor profile set --disable ' + ID)
- json_output = json.loads(self.openstack(
- 'network flavor profile show -f json ' + ID
- ))
+ json_output = self.openstack(
+ 'network flavor profile show ' + ID,
+ parse_output=True,
+ )
self.assertFalse(json_output.get('enabled'))
self.assertEqual(
'fakedescription',
@@ -141,17 +145,19 @@ class NetworkFlavorProfileTests(common.NetworkTests):
self.assertOutput('', raw_output)
def test_network_flavor_profile_show(self):
- json_output_1 = json.loads(self.openstack(
- 'network flavor profile create -f json ' +
+ json_output_1 = self.openstack(
+ 'network flavor profile create ' +
'--description ' + self.DESCRIPTION + ' ' +
'--enable ' +
- '--metainfo ' + self.METAINFO
- ))
+ '--metainfo ' + self.METAINFO,
+ parse_output=True,
+ )
ID = json_output_1.get('id')
self.assertIsNotNone(ID)
- json_output = json.loads(self.openstack(
- 'network flavor profile show -f json ' + ID
- ))
+ json_output = self.openstack(
+ 'network flavor profile show ' + ID,
+ parse_output=True,
+ )
self.assertEqual(
ID,
json_output["id"],
diff --git a/openstackclient/tests/functional/network/v2/test_network_meter.py b/openstackclient/tests/functional/network/v2/test_network_meter.py
index 0a8b89ca..ea9d289f 100644
--- a/openstackclient/tests/functional/network/v2/test_network_meter.py
+++ b/openstackclient/tests/functional/network/v2/test_network_meter.py
@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -38,11 +37,12 @@ class TestMeter(common.NetworkTests):
name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex
description = 'fakedescription'
- json_output = json.loads(self.openstack(
- 'network meter create -f json ' +
+ json_output = self.openstack(
+ 'network meter create ' +
' --description ' + description + ' ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
json_output.get('name'),
@@ -54,11 +54,12 @@ class TestMeter(common.NetworkTests):
json_output.get('description'),
)
- json_output_2 = json.loads(self.openstack(
- 'network meter create -f json ' +
+ json_output_2 = self.openstack(
+ 'network meter create ' +
'--description ' + description + ' ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
json_output_2.get('name'),
@@ -78,12 +79,13 @@ class TestMeter(common.NetworkTests):
def test_meter_list(self):
"""Test create, list filters, delete"""
name1 = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'network meter create -f json ' +
+ json_output = self.openstack(
+ 'network meter create ' +
'--description Test1 ' +
'--share ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'network meter delete ' + name1
@@ -96,12 +98,13 @@ class TestMeter(common.NetworkTests):
self.assertTrue(json_output.get('shared'))
name2 = uuid.uuid4().hex
- json_output_2 = json.loads(self.openstack(
- 'network meter create -f json ' +
+ json_output_2 = self.openstack(
+ 'network meter create ' +
'--description Test2 ' +
'--no-share ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'network meter delete ' + name2)
self.assertEqual(
@@ -112,7 +115,7 @@ class TestMeter(common.NetworkTests):
json_output_2.get('shared'),
)
- raw_output = json.loads(self.openstack('network meter list -f json'))
+ raw_output = self.openstack('network meter list', parse_output=True)
name_list = [item.get('Name') for item in raw_output]
self.assertIn(name1, name_list)
self.assertIn(name2, name_list)
@@ -121,18 +124,20 @@ class TestMeter(common.NetworkTests):
"""Test create, show, delete"""
name1 = uuid.uuid4().hex
description = 'fakedescription'
- json_output = json.loads(self.openstack(
- 'network meter create -f json ' +
+ json_output = self.openstack(
+ 'network meter create ' +
' --description ' + description + ' ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
meter_id = json_output.get('id')
self.addCleanup(self.openstack, 'network meter delete ' + name1)
# Test show with ID
- json_output = json.loads(self.openstack(
- 'network meter show -f json ' + meter_id
- ))
+ json_output = self.openstack(
+ 'network meter show ' + meter_id,
+ parse_output=True,
+ )
self.assertFalse(json_output.get('shared'))
self.assertEqual(
'fakedescription',
@@ -144,9 +149,10 @@ class TestMeter(common.NetworkTests):
)
# Test show with name
- json_output = json.loads(self.openstack(
- 'network meter show -f json ' + name1
- ))
+ json_output = self.openstack(
+ 'network meter show ' + name1,
+ parse_output=True,
+ )
self.assertEqual(
meter_id,
json_output.get('id'),
diff --git a/openstackclient/tests/functional/network/v2/test_network_meter_rule.py b/openstackclient/tests/functional/network/v2/test_network_meter_rule.py
index 31bc0845..ae1bb904 100644
--- a/openstackclient/tests/functional/network/v2/test_network_meter_rule.py
+++ b/openstackclient/tests/functional/network/v2/test_network_meter_rule.py
@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -31,10 +30,11 @@ class TestMeterRule(common.NetworkTests):
if cls.haz_network:
cls.METER_NAME = uuid.uuid4().hex
- json_output = json.loads(cls.openstack(
- 'network meter create -f json ' +
- cls.METER_NAME
- ))
+ json_output = cls.openstack(
+ 'network meter create ' +
+ cls.METER_NAME,
+ parse_output=True,
+ )
cls.METER_ID = json_output.get('id')
@classmethod
@@ -57,11 +57,12 @@ class TestMeterRule(common.NetworkTests):
def test_meter_rule_delete(self):
"""test create, delete"""
- json_output = json.loads(self.openstack(
- 'network meter rule create -f json ' +
+ json_output = self.openstack(
+ 'network meter rule create ' +
'--remote-ip-prefix 10.0.0.0/8 ' +
- self.METER_ID
- ))
+ self.METER_ID,
+ parse_output=True,
+ )
rule_id = json_output.get('id')
re_ip = json_output.get('remote_ip_prefix')
@@ -77,11 +78,12 @@ class TestMeterRule(common.NetworkTests):
def test_meter_rule_list(self):
"""Test create, list, delete"""
- json_output = json.loads(self.openstack(
- 'network meter rule create -f json ' +
+ json_output = self.openstack(
+ 'network meter rule create ' +
'--remote-ip-prefix 10.0.0.0/8 ' +
- self.METER_ID
- ))
+ self.METER_ID,
+ parse_output=True,
+ )
rule_id_1 = json_output.get('id')
self.addCleanup(
self.openstack,
@@ -92,11 +94,12 @@ class TestMeterRule(common.NetworkTests):
json_output.get('remote_ip_prefix')
)
- json_output_1 = json.loads(self.openstack(
- 'network meter rule create -f json ' +
+ json_output_1 = self.openstack(
+ 'network meter rule create ' +
'--remote-ip-prefix 11.0.0.0/8 ' +
- self.METER_ID
- ))
+ self.METER_ID,
+ parse_output=True,
+ )
rule_id_2 = json_output_1.get('id')
self.addCleanup(
self.openstack,
@@ -107,9 +110,10 @@ class TestMeterRule(common.NetworkTests):
json_output_1.get('remote_ip_prefix')
)
- json_output = json.loads(self.openstack(
- 'network meter rule list -f json'
- ))
+ json_output = self.openstack(
+ 'network meter rule list',
+ parse_output=True,
+ )
rule_id_list = [item.get('ID') for item in json_output]
ip_prefix_list = [item.get('Remote IP Prefix') for item in json_output]
self.assertIn(rule_id_1, rule_id_list)
@@ -119,12 +123,13 @@ class TestMeterRule(common.NetworkTests):
def test_meter_rule_show(self):
"""Test create, show, delete"""
- json_output = json.loads(self.openstack(
- 'network meter rule create -f json ' +
+ json_output = self.openstack(
+ 'network meter rule create ' +
'--remote-ip-prefix 10.0.0.0/8 ' +
'--egress ' +
- self.METER_ID
- ))
+ self.METER_ID,
+ parse_output=True,
+ )
rule_id = json_output.get('id')
self.assertEqual(
@@ -132,9 +137,10 @@ class TestMeterRule(common.NetworkTests):
json_output.get('direction')
)
- json_output = json.loads(self.openstack(
- 'network meter rule show -f json ' + rule_id
- ))
+ json_output = self.openstack(
+ 'network meter rule show ' + rule_id,
+ parse_output=True,
+ )
self.assertEqual(
'10.0.0.0/8',
json_output.get('remote_ip_prefix')
diff --git a/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py b/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py
index a10aef6b..588b1f56 100644
--- a/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py
+++ b/openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py
@@ -10,9 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-
-import json
-
from openstackclient.tests.functional.network.v2 import common
@@ -36,38 +33,45 @@ class L3NDPProxyTests(common.NetworkTests):
self.SUBNET_P_NAME = self.getUniqueString()
self.created_ndp_proxies = []
- json_output = json.loads(
- self.openstack(
- 'address scope create -f json --ip-version 6 '
- '%(address_s_name)s' % {
- 'address_s_name': self.ADDR_SCOPE_NAME}))
+ json_output = self.openstack(
+ 'address scope create --ip-version 6 '
+ '%(address_s_name)s' % {'address_s_name': self.ADDR_SCOPE_NAME},
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.ADDRESS_SCOPE_ID = json_output['id']
- json_output = json.loads(
- self.openstack(
- 'subnet pool create -f json %(subnet_p_name)s '
- '--address-scope %(address_scope)s '
- '--pool-prefix 2001:db8::/96 --default-prefix-length 112' % {
- 'subnet_p_name': self.SUBNET_P_NAME,
- 'address_scope': self.ADDRESS_SCOPE_ID}))
+ json_output = self.openstack(
+ 'subnet pool create %(subnet_p_name)s '
+ '--address-scope %(address_scope)s '
+ '--pool-prefix 2001:db8::/96 --default-prefix-length 112' % {
+ 'subnet_p_name': self.SUBNET_P_NAME,
+ 'address_scope': self.ADDRESS_SCOPE_ID,
+ },
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.SUBNET_POOL_ID = json_output['id']
- json_output = json.loads(
- self.openstack('network create -f json '
- '--external ' + self.EXT_NET_NAME))
+ json_output = self.openstack(
+ 'network create --external ' + self.EXT_NET_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.EXT_NET_ID = json_output['id']
- json_output = json.loads(
- self.openstack(
- 'subnet create -f json --ip-version 6 --subnet-pool '
- '%(subnet_pool)s --network %(net_id)s %(sub_name)s' % {
- 'subnet_pool': self.SUBNET_POOL_ID,
- 'net_id': self.EXT_NET_ID,
- 'sub_name': self.EXT_SUB_NAME}))
+ json_output = self.openstack(
+ 'subnet create --ip-version 6 --subnet-pool '
+ '%(subnet_pool)s --network %(net_id)s %(sub_name)s' % {
+ 'subnet_pool': self.SUBNET_POOL_ID,
+ 'net_id': self.EXT_NET_ID,
+ 'sub_name': self.EXT_SUB_NAME,
+ },
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.EXT_SUB_ID = json_output['id']
- json_output = json.loads(
- self.openstack('router create -f json ' + self.ROT_NAME))
+ json_output = self.openstack(
+ 'router create ' + self.ROT_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.ROT_ID = json_output['id']
output = self.openstack(
@@ -77,29 +81,36 @@ class L3NDPProxyTests(common.NetworkTests):
self.assertEqual('', output)
output = self.openstack('router set --enable-ndp-proxy ' + self.ROT_ID)
self.assertEqual('', output)
- json_output = json.loads(
- self.openstack(
- 'router show -f json -c enable_ndp_proxy ' + self.ROT_ID))
+ json_output = self.openstack(
+ 'router show -c enable_ndp_proxy ' + self.ROT_ID,
+ parse_output=True,
+ )
self.assertTrue(json_output['enable_ndp_proxy'])
- json_output = json.loads(
- self.openstack('network create -f json ' + self.INT_NET_NAME))
+ json_output = self.openstack(
+ 'network create ' + self.INT_NET_NAME,
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.INT_NET_ID = json_output['id']
- json_output = json.loads(
- self.openstack(
- 'subnet create -f json --ip-version 6 --subnet-pool '
- '%(subnet_pool)s --network %(net_id)s %(sub_name)s' % {
- 'subnet_pool': self.SUBNET_POOL_ID,
- 'net_id': self.INT_NET_ID,
- 'sub_name': self.INT_SUB_NAME}))
+ json_output = self.openstack(
+ 'subnet create --ip-version 6 --subnet-pool '
+ '%(subnet_pool)s --network %(net_id)s %(sub_name)s' % {
+ 'subnet_pool': self.SUBNET_POOL_ID,
+ 'net_id': self.INT_NET_ID,
+ 'sub_name': self.INT_SUB_NAME,
+ },
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.INT_SUB_ID = json_output['id']
- json_output = json.loads(
- self.openstack(
- 'port create -f json --network %(net_id)s '
- '%(port_name)s' % {
- 'net_id': self.INT_NET_ID,
- 'port_name': self.INT_PORT_NAME}))
+ json_output = self.openstack(
+ 'port create --network %(net_id)s '
+ '%(port_name)s' % {
+ 'net_id': self.INT_NET_ID,
+ 'port_name': self.INT_PORT_NAME,
+ },
+ parse_output=True,
+ )
self.assertIsNotNone(json_output['id'])
self.INT_PORT_ID = json_output['id']
self.INT_PORT_ADDRESS = json_output['fixed_ips'][0]['ip_address']
@@ -142,14 +153,16 @@ class L3NDPProxyTests(common.NetworkTests):
def _create_ndp_proxies(self, ndp_proxies):
for ndp_proxy in ndp_proxies:
- output = json.loads(
- self.openstack(
- 'router ndp proxy create %(router)s --name %(name)s '
- '--port %(port)s --ip-address %(address)s -f json' % {
- 'router': ndp_proxy['router_id'],
- 'name': ndp_proxy['name'],
- 'port': ndp_proxy['port_id'],
- 'address': ndp_proxy['address']}))
+ output = self.openstack(
+ 'router ndp proxy create %(router)s --name %(name)s '
+ '--port %(port)s --ip-address %(address)s' % {
+ 'router': ndp_proxy['router_id'],
+ 'name': ndp_proxy['name'],
+ 'port': ndp_proxy['port_id'],
+ 'address': ndp_proxy['address'],
+ },
+ parse_output=True,
+ )
self.assertEqual(ndp_proxy['router_id'], output['router_id'])
self.assertEqual(ndp_proxy['port_id'], output['port_id'])
self.assertEqual(ndp_proxy['address'], output['ip_address'])
@@ -173,8 +186,9 @@ class L3NDPProxyTests(common.NetworkTests):
'port_id': self.INT_PORT_ID,
'address': self.INT_PORT_ADDRESS}
self._create_ndp_proxies([ndp_proxies])
- ndp_proxy = json.loads(self.openstack(
- 'router ndp proxy list -f json'))[0]
+ ndp_proxy = self.openstack(
+ 'router ndp proxy list',
+ parse_output=True,)[0]
self.assertEqual(ndp_proxies['name'], ndp_proxy['Name'])
self.assertEqual(ndp_proxies['router_id'], ndp_proxy['Router ID'])
self.assertEqual(ndp_proxies['address'], ndp_proxy['IP Address'])
@@ -192,8 +206,10 @@ class L3NDPProxyTests(common.NetworkTests):
'router ndp proxy set --description %s %s' % (
description, ndp_proxy_id))
self.assertEqual('', output)
- json_output = json.loads(
- self.openstack('router ndp proxy show -f json ' + ndp_proxy_id))
+ json_output = self.openstack(
+ 'router ndp proxy show ' + ndp_proxy_id,
+ parse_output=True,
+ )
self.assertEqual(ndp_proxies['name'], json_output['name'])
self.assertEqual(ndp_proxies['router_id'], json_output['router_id'])
self.assertEqual(ndp_proxies['port_id'], json_output['port_id'])
diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_policy.py b/openstackclient/tests/functional/network/v2/test_network_qos_policy.py
index 02e64028..b603cf1f 100644
--- a/openstackclient/tests/functional/network/v2/test_network_qos_policy.py
+++ b/openstackclient/tests/functional/network/v2/test_network_qos_policy.py
@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -31,7 +30,7 @@ class NetworkQosPolicyTests(common.NetworkTests):
def test_qos_rule_create_delete(self):
# This is to check the output of qos policy delete
policy_name = uuid.uuid4().hex
- self.openstack('network qos policy create -f json ' + policy_name)
+ self.openstack('network qos policy create ' + policy_name)
raw_output = self.openstack(
'network qos policy delete ' +
policy_name
@@ -40,25 +39,28 @@ class NetworkQosPolicyTests(common.NetworkTests):
def test_qos_policy_list(self):
policy_name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'network qos policy create -f json ' +
- policy_name
- ))
+ json_output = self.openstack(
+ 'network qos policy create ' +
+ policy_name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'network qos policy delete ' + policy_name)
self.assertEqual(policy_name, json_output['name'])
- json_output = json.loads(self.openstack(
- 'network qos policy list -f json'
- ))
+ json_output = self.openstack(
+ 'network qos policy list',
+ parse_output=True,
+ )
self.assertIn(policy_name, [p['Name'] for p in json_output])
def test_qos_policy_set(self):
policy_name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'network qos policy create -f json ' +
- policy_name
- ))
+ json_output = self.openstack(
+ 'network qos policy create ' +
+ policy_name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'network qos policy delete ' + policy_name)
self.assertEqual(policy_name, json_output['name'])
@@ -69,10 +71,11 @@ class NetworkQosPolicyTests(common.NetworkTests):
policy_name
)
- json_output = json.loads(self.openstack(
- 'network qos policy show -f json ' +
- policy_name
- ))
+ json_output = self.openstack(
+ 'network qos policy show ' +
+ policy_name,
+ parse_output=True,
+ )
self.assertTrue(json_output['shared'])
self.openstack(
@@ -81,9 +84,10 @@ class NetworkQosPolicyTests(common.NetworkTests):
'--no-default ' +
policy_name
)
- json_output = json.loads(self.openstack(
- 'network qos policy show -f json ' +
- policy_name
- ))
+ json_output = self.openstack(
+ 'network qos policy show ' +
+ policy_name,
+ parse_output=True,
+ )
self.assertFalse(json_output['shared'])
self.assertFalse(json_output['is_default'])
diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py
index fd411b35..0fe1854b 100644
--- a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py
+++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py
@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -35,13 +34,14 @@ class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests):
)
self.addCleanup(self.openstack,
'network qos policy delete %s' % self.QOS_POLICY_NAME)
- cmd_output = json.loads(self.openstack(
- 'network qos rule create -f json '
+ cmd_output = self.openstack(
+ 'network qos rule create '
'--type minimum-bandwidth '
'--min-kbps 2800 '
'--egress %s' %
- self.QOS_POLICY_NAME
- ))
+ self.QOS_POLICY_NAME,
+ parse_output=True,
+ )
self.RULE_ID = cmd_output['id']
self.addCleanup(self.openstack,
'network qos rule delete %s %s' %
@@ -51,37 +51,43 @@ class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests):
def test_qos_rule_create_delete(self):
# This is to check the output of qos rule delete
policy_name = uuid.uuid4().hex
- self.openstack('network qos policy create -f json %s' % policy_name)
+ self.openstack('network qos policy create %s' % policy_name)
self.addCleanup(self.openstack,
'network qos policy delete %s' % policy_name)
- rule = json.loads(self.openstack(
- 'network qos rule create -f json '
+ rule = self.openstack(
+ 'network qos rule create '
'--type minimum-bandwidth '
'--min-kbps 2800 '
- '--egress %s' % policy_name
- ))
+ '--egress %s' % policy_name,
+ parse_output=True,
+ )
raw_output = self.openstack(
'network qos rule delete %s %s' %
(policy_name, rule['id']))
self.assertEqual('', raw_output)
def test_qos_rule_list(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule list -f json %s' % self.QOS_POLICY_NAME))
+ cmd_output = self.openstack(
+ 'network qos rule list %s' % self.QOS_POLICY_NAME,
+ parse_output=True,)
self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output])
def test_qos_rule_show(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(self.RULE_ID, cmd_output['id'])
def test_qos_rule_set(self):
self.openstack('network qos rule set --min-kbps 7500 %s %s' %
(self.QOS_POLICY_NAME, self.RULE_ID))
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(7500, cmd_output['min_kbps'])
@@ -101,13 +107,14 @@ class NetworkQosRuleTestsMinimumPacketRate(common.NetworkTests):
)
self.addCleanup(self.openstack,
'network qos policy delete %s' % self.QOS_POLICY_NAME)
- cmd_output = json.loads(self.openstack(
- 'network qos rule create -f json '
+ cmd_output = self.openstack(
+ 'network qos rule create '
'--type minimum-packet-rate '
'--min-kpps 2800 '
'--egress %s' %
- self.QOS_POLICY_NAME
- ))
+ self.QOS_POLICY_NAME,
+ parse_output=True,
+ )
self.RULE_ID = cmd_output['id']
self.addCleanup(self.openstack,
'network qos rule delete %s %s' %
@@ -117,37 +124,43 @@ class NetworkQosRuleTestsMinimumPacketRate(common.NetworkTests):
def test_qos_rule_create_delete(self):
# This is to check the output of qos rule delete
policy_name = uuid.uuid4().hex
- self.openstack('network qos policy create -f json %s' % policy_name)
+ self.openstack('network qos policy create %s' % policy_name)
self.addCleanup(self.openstack,
'network qos policy delete %s' % policy_name)
- rule = json.loads(self.openstack(
- 'network qos rule create -f json '
+ rule = self.openstack(
+ 'network qos rule create '
'--type minimum-packet-rate '
'--min-kpps 2800 '
- '--egress %s' % policy_name
- ))
+ '--egress %s' % policy_name,
+ parse_output=True,
+ )
raw_output = self.openstack(
'network qos rule delete %s %s' %
(policy_name, rule['id']))
self.assertEqual('', raw_output)
def test_qos_rule_list(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule list -f json %s' % self.QOS_POLICY_NAME))
+ cmd_output = self.openstack(
+ 'network qos rule list %s' % self.QOS_POLICY_NAME,
+ parse_output=True,)
self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output])
def test_qos_rule_show(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(self.RULE_ID, cmd_output['id'])
def test_qos_rule_set(self):
self.openstack('network qos rule set --min-kpps 7500 --any %s %s' %
(self.QOS_POLICY_NAME, self.RULE_ID))
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(7500, cmd_output['min_kpps'])
self.assertEqual('any', cmd_output['direction'])
@@ -167,12 +180,13 @@ class NetworkQosRuleTestsDSCPMarking(common.NetworkTests):
)
self.addCleanup(self.openstack,
'network qos policy delete %s' % self.QOS_POLICY_NAME)
- cmd_output = json.loads(self.openstack(
- 'network qos rule create -f json '
+ cmd_output = self.openstack(
+ 'network qos rule create '
'--type dscp-marking '
'--dscp-mark 8 %s' %
- self.QOS_POLICY_NAME
- ))
+ self.QOS_POLICY_NAME,
+ parse_output=True,
+ )
self.RULE_ID = cmd_output['id']
self.addCleanup(self.openstack,
'network qos rule delete %s %s' %
@@ -182,36 +196,42 @@ class NetworkQosRuleTestsDSCPMarking(common.NetworkTests):
def test_qos_rule_create_delete(self):
# This is to check the output of qos rule delete
policy_name = uuid.uuid4().hex
- self.openstack('network qos policy create -f json %s' % policy_name)
+ self.openstack('network qos policy create %s' % policy_name)
self.addCleanup(self.openstack,
'network qos policy delete %s' % policy_name)
- rule = json.loads(self.openstack(
- 'network qos rule create -f json '
+ rule = self.openstack(
+ 'network qos rule create '
'--type dscp-marking '
- '--dscp-mark 8 %s' % policy_name
- ))
+ '--dscp-mark 8 %s' % policy_name,
+ parse_output=True,
+ )
raw_output = self.openstack(
'network qos rule delete %s %s' %
(policy_name, rule['id']))
self.assertEqual('', raw_output)
def test_qos_rule_list(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule list -f json %s' % self.QOS_POLICY_NAME))
+ cmd_output = self.openstack(
+ 'network qos rule list %s' % self.QOS_POLICY_NAME,
+ parse_output=True,)
self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output])
def test_qos_rule_show(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(self.RULE_ID, cmd_output['id'])
def test_qos_rule_set(self):
self.openstack('network qos rule set --dscp-mark 32 %s %s' %
(self.QOS_POLICY_NAME, self.RULE_ID))
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(32, cmd_output['dscp_mark'])
@@ -230,13 +250,14 @@ class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests):
)
self.addCleanup(self.openstack,
'network qos policy delete %s' % self.QOS_POLICY_NAME)
- cmd_output = json.loads(self.openstack(
- 'network qos rule create -f json '
+ cmd_output = self.openstack(
+ 'network qos rule create '
'--type bandwidth-limit '
'--max-kbps 10000 '
'--egress %s' %
- self.QOS_POLICY_NAME
- ))
+ self.QOS_POLICY_NAME,
+ parse_output=True,
+ )
self.RULE_ID = cmd_output['id']
self.addCleanup(self.openstack,
'network qos rule delete %s %s' %
@@ -246,31 +267,35 @@ class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests):
def test_qos_rule_create_delete(self):
# This is to check the output of qos rule delete
policy_name = uuid.uuid4().hex
- self.openstack('network qos policy create -f json %s' % policy_name)
+ self.openstack('network qos policy create %s' % policy_name)
self.addCleanup(self.openstack,
'network qos policy delete %s' % policy_name)
- rule = json.loads(self.openstack(
- 'network qos rule create -f json '
+ rule = self.openstack(
+ 'network qos rule create '
'--type bandwidth-limit '
'--max-kbps 10000 '
'--max-burst-kbits 1400 '
- '--egress %s' % policy_name
- ))
+ '--egress %s' % policy_name,
+ parse_output=True,
+ )
raw_output = self.openstack(
'network qos rule delete %s %s' %
(policy_name, rule['id']))
self.assertEqual('', raw_output)
def test_qos_rule_list(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule list -f json %s' %
- self.QOS_POLICY_NAME))
+ cmd_output = self.openstack(
+ 'network qos rule list %s' %
+ self.QOS_POLICY_NAME,
+ parse_output=True,)
self.assertIn(self.RULE_ID, [rule['ID'] for rule in cmd_output])
def test_qos_rule_show(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(self.RULE_ID, cmd_output['id'])
def test_qos_rule_set(self):
@@ -278,9 +303,11 @@ class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests):
'--max-burst-kbits 1800 '
'--ingress %s %s' %
(self.QOS_POLICY_NAME, self.RULE_ID))
- cmd_output = json.loads(self.openstack(
- 'network qos rule show -f json %s %s' %
- (self.QOS_POLICY_NAME, self.RULE_ID)))
+ cmd_output = self.openstack(
+ 'network qos rule show %s %s' %
+ (self.QOS_POLICY_NAME, self.RULE_ID),
+ parse_output=True,
+ )
self.assertEqual(15000, cmd_output['max_kbps'])
self.assertEqual(1800, cmd_output['max_burst_kbps'])
self.assertEqual('ingress', cmd_output['direction'])
diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py
index 56cd8920..4ead65cc 100644
--- a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py
+++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from openstackclient.tests.functional.network.v2 import common
@@ -23,6 +21,13 @@ class NetworkQosRuleTypeTests(common.NetworkTests):
AVAILABLE_RULE_TYPES = ['dscp_marking',
'bandwidth_limit']
+ # NOTE(ralonsoh): this list was updated in Yoga (February 2022)
+ ALL_AVAILABLE_RULE_TYPES = ['dscp_marking',
+ 'bandwidth_limit',
+ 'minimum_bandwidth',
+ 'packet_rate_limit',
+ 'minimum_packet_rate',
+ ]
def setUp(self):
super(NetworkQosRuleTypeTests, self).setUp()
@@ -31,14 +36,40 @@ class NetworkQosRuleTypeTests(common.NetworkTests):
self.skipTest("No Network service present")
def test_qos_rule_type_list(self):
- cmd_output = json.loads(self.openstack(
- 'network qos rule type list -f json'))
+ cmd_output = self.openstack(
+ 'network qos rule type list -f json',
+ parse_output=True,
+ )
+ for rule_type in self.AVAILABLE_RULE_TYPES:
+ self.assertIn(rule_type, [x['Type'] for x in cmd_output])
+
+ def test_qos_rule_type_list_all_supported(self):
+ if not self.is_extension_enabled('qos-rule-type-filter'):
+ self.skipTest('No "qos-rule-type-filter" extension present')
+
+ cmd_output = self.openstack(
+ 'network qos rule type list --all-supported -f json',
+ parse_output=True
+ )
for rule_type in self.AVAILABLE_RULE_TYPES:
self.assertIn(rule_type, [x['Type'] for x in cmd_output])
+ def test_qos_rule_type_list_all_rules(self):
+ if not self.is_extension_enabled('qos-rule-type-filter'):
+ self.skipTest('No "qos-rule-type-filter" extension present')
+
+ cmd_output = self.openstack(
+ 'network qos rule type list --all-rules -f json',
+ parse_output=True
+ )
+ for rule_type in self.ALL_AVAILABLE_RULE_TYPES:
+ self.assertIn(rule_type, [x['Type'] for x in cmd_output])
+
def test_qos_rule_type_details(self):
for rule_type in self.AVAILABLE_RULE_TYPES:
- cmd_output = json.loads(self.openstack(
- 'network qos rule type show %s -f json' % rule_type))
+ cmd_output = self.openstack(
+ 'network qos rule type show %s -f json' % rule_type,
+ parse_output=True,
+ )
self.assertEqual(rule_type, cmd_output['rule_type_name'])
self.assertIn("drivers", cmd_output.keys())
diff --git a/openstackclient/tests/functional/network/v2/test_network_rbac.py b/openstackclient/tests/functional/network/v2/test_network_rbac.py
index 3bbe4f27..cb66759a 100644
--- a/openstackclient/tests/functional/network/v2/test_network_rbac.py
+++ b/openstackclient/tests/functional/network/v2/test_network_rbac.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -32,41 +31,47 @@ class NetworkRBACTests(common.NetworkTests):
self.NET_NAME = uuid.uuid4().hex
self.PROJECT_NAME = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'network create -f json ' + self.NET_NAME
- ))
+ cmd_output = self.openstack(
+ 'network create ' + self.NET_NAME,
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'network delete ' + cmd_output['id'])
self.OBJECT_ID = cmd_output['id']
- cmd_output = json.loads(self.openstack(
- 'network rbac create -f json ' +
+ cmd_output = self.openstack(
+ 'network rbac create ' +
self.OBJECT_ID +
' --action access_as_shared' +
' --target-project admin' +
- ' --type network'
- ))
+ ' --type network',
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'network rbac delete ' + cmd_output['id'])
self.ID = cmd_output['id']
self.assertEqual(self.OBJECT_ID, cmd_output['object_id'])
def test_network_rbac_list(self):
- cmd_output = json.loads(self.openstack('network rbac list -f json'))
+ cmd_output = self.openstack('network rbac list', parse_output=True)
self.assertIn(self.ID, [rbac['ID'] for rbac in cmd_output])
def test_network_rbac_show(self):
- cmd_output = json.loads(self.openstack(
- 'network rbac show -f json ' + self.ID))
+ cmd_output = self.openstack(
+ 'network rbac show ' + self.ID,
+ parse_output=True,)
self.assertEqual(self.ID, cmd_output['id'])
def test_network_rbac_set(self):
- project_id = json.loads(self.openstack(
- 'project create -f json ' + self.PROJECT_NAME))['id']
+ project_id = self.openstack(
+ 'project create ' + self.PROJECT_NAME,
+ parse_output=True,)['id']
self.openstack('network rbac set ' + self.ID +
' --target-project ' + self.PROJECT_NAME)
- cmd_output_rbac = json.loads(self.openstack(
- 'network rbac show -f json ' + self.ID))
+ cmd_output_rbac = self.openstack(
+ 'network rbac show ' + self.ID,
+ parse_output=True,
+ )
self.assertEqual(project_id, cmd_output_rbac['target_project_id'])
raw_output_project = self.openstack(
'project delete ' + self.PROJECT_NAME)
diff --git a/openstackclient/tests/functional/network/v2/test_network_segment.py b/openstackclient/tests/functional/network/v2/test_network_segment.py
index 6ffb11cf..111c4dc3 100644
--- a/openstackclient/tests/functional/network/v2/test_network_segment.py
+++ b/openstackclient/tests/functional/network/v2/test_network_segment.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -27,10 +26,9 @@ class NetworkSegmentTests(common.NetworkTests):
cls.PHYSICAL_NETWORK_NAME = uuid.uuid4().hex
# Create a network for the all subnet tests
- cmd_output = json.loads(cls.openstack(
- 'network create -f json ' +
- cls.NETWORK_NAME
- ))
+ cmd_output = cls.openstack(
+ 'network create ' + cls.NETWORK_NAME, parse_output=True,
+ )
# Get network_id for assertEqual
cls.NETWORK_ID = cmd_output["id"]
@@ -54,13 +52,14 @@ class NetworkSegmentTests(common.NetworkTests):
def test_network_segment_create_delete(self):
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- ' network segment create -f json ' +
+ json_output = self.openstack(
+ ' network segment create ' +
'--network ' + self.NETWORK_ID + ' ' +
'--network-type geneve ' +
'--segment 2055 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
json_output["name"],
@@ -73,13 +72,14 @@ class NetworkSegmentTests(common.NetworkTests):
def test_network_segment_list(self):
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- ' network segment create -f json ' +
+ json_output = self.openstack(
+ ' network segment create ' +
'--network ' + self.NETWORK_ID + ' ' +
'--network-type geneve ' +
'--segment 2055 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
network_segment_id = json_output.get('id')
network_segment_name = json_output.get('name')
self.addCleanup(
@@ -91,9 +91,10 @@ class NetworkSegmentTests(common.NetworkTests):
json_output["name"],
)
- json_output = json.loads(self.openstack(
- 'network segment list -f json'
- ))
+ json_output = self.openstack(
+ 'network segment list',
+ parse_output=True,
+ )
item_map = {
item.get('ID'): item.get('Name') for item in json_output
}
@@ -102,21 +103,23 @@ class NetworkSegmentTests(common.NetworkTests):
def test_network_segment_set_show(self):
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- ' network segment create -f json ' +
+ json_output = self.openstack(
+ ' network segment create ' +
'--network ' + self.NETWORK_ID + ' ' +
'--network-type geneve ' +
'--segment 2055 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'network segment delete ' + name
)
- extension_output = json.loads(self.openstack(
- "extension list -f json "
- ))
+ extension_output = self.openstack(
+ "extension list ",
+ parse_output=True,
+ )
ext_alias = [x["Alias"] for x in extension_output]
if "standard-attr-segment" in ext_alias:
self.assertEqual(
@@ -136,10 +139,11 @@ class NetworkSegmentTests(common.NetworkTests):
)
self.assertOutput('', cmd_output)
- json_output = json.loads(self.openstack(
- 'network segment show -f json ' +
- name
- ))
+ json_output = self.openstack(
+ 'network segment show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
new_description,
json_output["description"],
diff --git a/openstackclient/tests/functional/network/v2/test_network_segment_range.py b/openstackclient/tests/functional/network/v2/test_network_segment_range.py
index 37c87dd5..5cdf5812 100644
--- a/openstackclient/tests/functional/network/v2/test_network_segment_range.py
+++ b/openstackclient/tests/functional/network/v2/test_network_segment_range.py
@@ -14,7 +14,6 @@
# under the License.
#
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -34,18 +33,20 @@ class NetworkSegmentRangeTests(common.NetworkTests):
def test_network_segment_range_create_delete(self):
# Make a project
- project_id = json.loads(self.openstack(
- 'project create -f json ' + self.PROJECT_NAME))['id']
+ project_id = self.openstack(
+ 'project create ' + self.PROJECT_NAME,
+ parse_output=True,)['id']
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- ' network segment range create -f json ' +
+ json_output = self.openstack(
+ ' network segment range create ' +
'--private ' +
"--project " + self.PROJECT_NAME + " " +
'--network-type vxlan ' +
'--minimum 2005 ' +
'--maximum 2009 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
json_output["name"],
@@ -65,14 +66,15 @@ class NetworkSegmentRangeTests(common.NetworkTests):
def test_network_segment_range_list(self):
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- ' network segment range create -f json ' +
+ json_output = self.openstack(
+ ' network segment range create ' +
'--shared ' +
'--network-type geneve ' +
'--minimum 2013 ' +
'--maximum 2017 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
network_segment_range_id = json_output.get('id')
network_segment_range_name = json_output.get('name')
self.addCleanup(
@@ -84,9 +86,10 @@ class NetworkSegmentRangeTests(common.NetworkTests):
json_output["name"],
)
- json_output = json.loads(self.openstack(
- 'network segment range list -f json'
- ))
+ json_output = self.openstack(
+ 'network segment range list',
+ parse_output=True,
+ )
item_map = {
item.get('ID'): item.get('Name') for item in json_output
}
@@ -94,18 +97,20 @@ class NetworkSegmentRangeTests(common.NetworkTests):
self.assertIn(network_segment_range_name, item_map.values())
def test_network_segment_range_set_show(self):
- project_id = json.loads(self.openstack(
- 'project create -f json ' + self.PROJECT_NAME))['id']
+ project_id = self.openstack(
+ 'project create ' + self.PROJECT_NAME,
+ parse_output=True,)['id']
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- ' network segment range create -f json ' +
+ json_output = self.openstack(
+ ' network segment range create ' +
'--private ' +
"--project " + self.PROJECT_NAME + " " +
'--network-type geneve ' +
'--minimum 2021 ' +
'--maximum 2025 ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'network segment range delete ' + name
@@ -127,10 +132,11 @@ class NetworkSegmentRangeTests(common.NetworkTests):
)
self.assertOutput('', cmd_output)
- json_output = json.loads(self.openstack(
- 'network segment range show -f json ' +
- name
- ))
+ json_output = self.openstack(
+ 'network segment range show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
new_minimum,
json_output["minimum"],
diff --git a/openstackclient/tests/functional/network/v2/test_network_service_provider.py b/openstackclient/tests/functional/network/v2/test_network_service_provider.py
index c571a756..9d513564 100644
--- a/openstackclient/tests/functional/network/v2/test_network_service_provider.py
+++ b/openstackclient/tests/functional/network/v2/test_network_service_provider.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from openstackclient.tests.functional.network.v2 import common
@@ -29,13 +27,15 @@ class TestNetworkServiceProvider(common.NetworkTests):
# NOTE(slaweq):
# that tests should works only when "standard" Neutron L3 agent is
# used, as e.g. OVN L3 plugin don't supports that.
- l3_agent_list = json.loads(self.openstack(
- 'network agent list -f json --agent-type l3 -c ID'
- ))
+ l3_agent_list = self.openstack(
+ 'network agent list --agent-type l3 -c ID',
+ parse_output=True,
+ )
if not l3_agent_list:
self.skipTest("No Neutron L3 Agents present")
def test_network_service_provider_list(self):
- cmd_output = json.loads(self.openstack(
- 'network service provider list -f json'))
+ cmd_output = self.openstack(
+ 'network service provider list',
+ parse_output=True,)
self.assertIn('L3_ROUTER_NAT', [x['Service Type'] for x in cmd_output])
diff --git a/openstackclient/tests/functional/network/v2/test_network_trunk.py b/openstackclient/tests/functional/network/v2/test_network_trunk.py
new file mode 100644
index 00000000..bbb77a0d
--- /dev/null
+++ b/openstackclient/tests/functional/network/v2/test_network_trunk.py
@@ -0,0 +1,149 @@
+# 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 json
+import uuid
+
+from openstackclient.tests.functional.network.v2 import common
+
+
+class NetworkTrunkTests(common.NetworkTests):
+ """Functional tests for Network Trunks"""
+
+ def setUp(self):
+ super().setUp()
+ # Nothing in this class works with Nova Network
+ if not self.haz_network:
+ self.skipTest("No Network service present")
+
+ network_name = uuid.uuid4().hex
+ subnet_name = uuid.uuid4().hex
+ self.parent_port_name = uuid.uuid4().hex
+ self.sub_port_name = uuid.uuid4().hex
+
+ self.openstack('network create %s' % network_name)
+ self.addCleanup(self.openstack, 'network delete %s' % network_name)
+
+ self.openstack(
+ 'subnet create %s '
+ '--network %s --subnet-range 10.0.0.0/24' % (
+ subnet_name, network_name))
+ self.openstack('port create %s --network %s' %
+ (self.parent_port_name, network_name))
+ self.addCleanup(self.openstack, 'port delete %s' %
+ self.parent_port_name)
+ json_out = self.openstack('port create %s --network %s -f json' %
+ (self.sub_port_name, network_name))
+ self.sub_port_id = json.loads(json_out)['id']
+ self.addCleanup(self.openstack, 'port delete %s' % self.sub_port_name)
+
+ def test_network_trunk_create_delete(self):
+ trunk_name = uuid.uuid4().hex
+ self.openstack('network trunk create %s --parent-port %s -f json ' %
+ (trunk_name, self.parent_port_name))
+ raw_output = self.openstack(
+ 'network trunk delete ' +
+ trunk_name
+ )
+ self.assertEqual('', raw_output)
+
+ def test_network_trunk_list(self):
+ trunk_name = uuid.uuid4().hex
+ json_output = json.loads(self.openstack(
+ 'network trunk create %s --parent-port %s -f json ' %
+ (trunk_name, self.parent_port_name)))
+ self.addCleanup(self.openstack,
+ 'network trunk delete ' + trunk_name)
+ self.assertEqual(trunk_name, json_output['name'])
+
+ json_output = json.loads(self.openstack(
+ 'network trunk list -f json'
+ ))
+ self.assertIn(trunk_name, [tr['Name'] for tr in json_output])
+
+ def test_network_trunk_set_unset(self):
+ trunk_name = uuid.uuid4().hex
+ json_output = json.loads(self.openstack(
+ 'network trunk create %s --parent-port %s -f json ' %
+ (trunk_name, self.parent_port_name)))
+ self.addCleanup(self.openstack,
+ 'network trunk delete ' + trunk_name)
+ self.assertEqual(trunk_name, json_output['name'])
+
+ self.openstack(
+ 'network trunk set '
+ '--enable ' +
+ trunk_name
+ )
+
+ json_output = json.loads(self.openstack(
+ 'network trunk show -f json ' +
+ trunk_name
+ ))
+ self.assertTrue(json_output['is_admin_state_up'])
+
+ # Add subport to trunk
+ self.openstack(
+ 'network trunk set ' +
+ '--subport port=%s,segmentation-type=vlan,segmentation-id=42 ' %
+ (self.sub_port_name) +
+ trunk_name
+ )
+ json_output = json.loads(self.openstack(
+ 'network trunk show -f json ' +
+ trunk_name
+ ))
+ self.assertEqual(
+ [{
+ 'port_id': self.sub_port_id,
+ 'segmentation_id': 42,
+ 'segmentation_type': 'vlan'
+ }],
+ json_output['sub_ports'])
+
+ # Remove subport from trunk
+ self.openstack(
+ 'network trunk unset ' +
+ trunk_name +
+ ' --subport ' +
+ self.sub_port_name
+ )
+ json_output = json.loads(self.openstack(
+ 'network trunk show -f json ' +
+ trunk_name
+ ))
+ self.assertEqual(
+ [],
+ json_output['sub_ports'])
+
+ def test_network_trunk_list_subports(self):
+ trunk_name = uuid.uuid4().hex
+ json_output = json.loads(self.openstack(
+ 'network trunk create %s --parent-port %s '
+ '--subport port=%s,segmentation-type=vlan,segmentation-id=42 '
+ '-f json ' %
+ (trunk_name, self.parent_port_name, self.sub_port_name)))
+ self.addCleanup(self.openstack,
+ 'network trunk delete ' + trunk_name)
+ self.assertEqual(trunk_name, json_output['name'])
+
+ json_output = json.loads(self.openstack(
+ 'network subport list --trunk %s -f json' % trunk_name))
+ self.assertEqual(
+ [{
+ 'Port': self.sub_port_id,
+ 'Segmentation ID': 42,
+ 'Segmentation Type': 'vlan'
+ }],
+ json_output)
diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py
index a20d2043..f5bc9c4a 100644
--- a/openstackclient/tests/functional/network/v2/test_port.py
+++ b/openstackclient/tests/functional/network/v2/test_port.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -55,19 +54,21 @@ class PortTests(common.NetworkTagTests):
def test_port_delete(self):
"""Test create, delete multiple"""
- json_output = json.loads(self.openstack(
- 'port create -f json --network %s %s' %
- (self.NETWORK_NAME, self.NAME)
- ))
+ json_output = self.openstack(
+ 'port create --network %s %s' %
+ (self.NETWORK_NAME, self.NAME),
+ parse_output=True,
+ )
id1 = json_output.get('id')
self.assertIsNotNone(id1)
self.assertIsNotNone(json_output.get('mac_address'))
self.assertEqual(self.NAME, json_output.get('name'))
- json_output = json.loads(self.openstack(
- 'port create -f json --network %s %sx' %
- (self.NETWORK_NAME, self.NAME)
- ))
+ json_output = self.openstack(
+ 'port create --network %s %sx' %
+ (self.NETWORK_NAME, self.NAME),
+ parse_output=True,
+ )
id2 = json_output.get('id')
self.assertIsNotNone(id2)
self.assertIsNotNone(json_output.get('mac_address'))
@@ -79,10 +80,11 @@ class PortTests(common.NetworkTagTests):
def test_port_list(self):
"""Test create defaults, list, delete"""
- json_output = json.loads(self.openstack(
- 'port create -f json --network %s %s' %
- (self.NETWORK_NAME, self.NAME)
- ))
+ json_output = self.openstack(
+ 'port create --network %s %s' %
+ (self.NETWORK_NAME, self.NAME),
+ parse_output=True,
+ )
id1 = json_output.get('id')
self.assertIsNotNone(id1)
mac1 = json_output.get('mac_address')
@@ -90,10 +92,11 @@ class PortTests(common.NetworkTagTests):
self.addCleanup(self.openstack, 'port delete %s' % id1)
self.assertEqual(self.NAME, json_output.get('name'))
- json_output = json.loads(self.openstack(
- 'port create -f json --network %s %sx' %
- (self.NETWORK_NAME, self.NAME)
- ))
+ json_output = self.openstack(
+ 'port create --network %s %sx' %
+ (self.NETWORK_NAME, self.NAME),
+ parse_output=True,
+ )
id2 = json_output.get('id')
self.assertIsNotNone(id2)
mac2 = json_output.get('mac_address')
@@ -102,9 +105,10 @@ class PortTests(common.NetworkTagTests):
self.assertEqual(self.NAME + 'x', json_output.get('name'))
# Test list
- json_output = json.loads(self.openstack(
- 'port list -f json'
- ))
+ json_output = self.openstack(
+ 'port list',
+ parse_output=True,
+ )
item_map = {item.get('ID'): item.get('MAC Address') for item in
json_output}
self.assertIn(id1, item_map.keys())
@@ -113,17 +117,19 @@ class PortTests(common.NetworkTagTests):
self.assertIn(mac2, item_map.values())
# Test list --long
- json_output = json.loads(self.openstack(
- 'port list --long -f json'
- ))
+ json_output = self.openstack(
+ 'port list --long',
+ parse_output=True,
+ )
id_list = [item.get('ID') for item in json_output]
self.assertIn(id1, id_list)
self.assertIn(id2, id_list)
# Test list --mac-address
- json_output = json.loads(self.openstack(
- 'port list -f json --mac-address %s' % mac2
- ))
+ json_output = self.openstack(
+ 'port list --mac-address %s' % mac2,
+ parse_output=True,
+ )
item_map = {item.get('ID'): item.get('MAC Address') for item in
json_output}
self.assertNotIn(id1, item_map.keys())
@@ -132,9 +138,10 @@ class PortTests(common.NetworkTagTests):
self.assertIn(mac2, item_map.values())
# Test list with unknown fields
- json_output = json.loads(self.openstack(
- 'port list -f json -c ID -c Name -c device_id'
- ))
+ json_output = self.openstack(
+ 'port list -c ID -c Name -c device_id',
+ parse_output=True,
+ )
id_list = [p['ID'] for p in json_output]
self.assertIn(id1, id_list)
self.assertIn(id2, id_list)
@@ -144,13 +151,14 @@ class PortTests(common.NetworkTagTests):
def test_port_set(self):
"""Test create, set, show, delete"""
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'port create -f json '
+ json_output = self.openstack(
+ 'port create '
'--network %s '
'--description xyzpdq '
'--disable %s' %
- (self.NETWORK_NAME, name)
- ))
+ (self.NETWORK_NAME, name),
+ parse_output=True,
+ )
id1 = json_output.get('id')
self.addCleanup(self.openstack, 'port delete %s' % id1)
self.assertEqual(name, json_output.get('name'))
@@ -163,9 +171,10 @@ class PortTests(common.NetworkTagTests):
)
self.assertOutput('', raw_output)
- json_output = json.loads(self.openstack(
- 'port show -f json %s' % name
- ))
+ json_output = self.openstack(
+ 'port show %s' % name,
+ parse_output=True,
+ )
sg_id = json_output.get('security_group_ids')[0]
self.assertEqual(name, json_output.get('name'))
@@ -177,17 +186,19 @@ class PortTests(common.NetworkTagTests):
'port unset --security-group %s %s' % (sg_id, id1))
self.assertOutput('', raw_output)
- json_output = json.loads(self.openstack(
- 'port show -f json %s' % name
- ))
+ json_output = self.openstack(
+ 'port show %s' % name,
+ parse_output=True,
+ )
self.assertEqual([], json_output.get('security_group_ids'))
def test_port_admin_set(self):
"""Test create, set (as admin), show, delete"""
- json_output = json.loads(self.openstack(
- 'port create -f json '
- '--network %s %s' % (self.NETWORK_NAME, self.NAME)
- ))
+ json_output = self.openstack(
+ 'port create '
+ '--network %s %s' % (self.NETWORK_NAME, self.NAME),
+ parse_output=True,
+ )
id_ = json_output.get('id')
self.addCleanup(self.openstack, 'port delete %s' % id_)
@@ -196,36 +207,40 @@ class PortTests(common.NetworkTagTests):
'port set --mac-address 11:22:33:44:55:66 %s' %
self.NAME)
self.assertOutput('', raw_output)
- json_output = json.loads(self.openstack(
- 'port show -f json %s' % self.NAME
- ))
+ json_output = self.openstack(
+ 'port show %s' % self.NAME,
+ parse_output=True,
+ )
self.assertEqual(json_output.get('mac_address'), '11:22:33:44:55:66')
def test_port_set_sg(self):
"""Test create, set, show, delete"""
sg_name1 = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'security group create -f json %s' %
- sg_name1
- ))
+ json_output = self.openstack(
+ 'security group create %s' %
+ sg_name1,
+ parse_output=True,
+ )
sg_id1 = json_output.get('id')
self.addCleanup(self.openstack, 'security group delete %s' % sg_id1)
sg_name2 = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'security group create -f json %s' %
- sg_name2
- ))
+ json_output = self.openstack(
+ 'security group create %s' %
+ sg_name2,
+ parse_output=True,
+ )
sg_id2 = json_output.get('id')
self.addCleanup(self.openstack, 'security group delete %s' % sg_id2)
name = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'port create -f json '
+ json_output = self.openstack(
+ 'port create '
'--network %s '
'--security-group %s %s' %
- (self.NETWORK_NAME, sg_name1, name)
- ))
+ (self.NETWORK_NAME, sg_name1, name),
+ parse_output=True,
+ )
id1 = json_output.get('id')
self.addCleanup(self.openstack, 'port delete %s' % id1)
self.assertEqual(name, json_output.get('name'))
@@ -238,9 +253,10 @@ class PortTests(common.NetworkTagTests):
)
self.assertOutput('', raw_output)
- json_output = json.loads(self.openstack(
- 'port show -f json %s' % name
- ))
+ json_output = self.openstack(
+ 'port show %s' % name,
+ parse_output=True,
+ )
self.assertEqual(name, json_output.get('name'))
# NOTE(amotoki): The order of the field is not predictable,
self.assertIsInstance(json_output.get('security_group_ids'), list)
@@ -251,16 +267,18 @@ class PortTests(common.NetworkTagTests):
'port unset --security-group %s %s' % (sg_id1, id1))
self.assertOutput('', raw_output)
- json_output = json.loads(self.openstack(
- 'port show -f json %s' % name
- ))
+ json_output = self.openstack(
+ 'port show %s' % name,
+ parse_output=True,
+ )
self.assertEqual(
[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)
- ))
+ return self.openstack(
+ '{} create --network {} {} {}'
+ .format(self.base_command, self.NETWORK_NAME, args, name),
+ parse_output=True,
+ )
diff --git a/openstackclient/tests/functional/network/v2/test_router.py b/openstackclient/tests/functional/network/v2/test_router.py
index 2464b681..07a5a633 100644
--- a/openstackclient/tests/functional/network/v2/test_router.py
+++ b/openstackclient/tests/functional/network/v2/test_router.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -31,18 +30,20 @@ class RouterTests(common.NetworkTagTests):
"""Test create options, delete multiple"""
name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'router create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'router create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output["name"],
)
- cmd_output = json.loads(self.openstack(
- 'router create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'router create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output["name"],
@@ -55,10 +56,10 @@ class RouterTests(common.NetworkTagTests):
def test_router_list(self):
"""Test create, list filter"""
# Get project IDs
- cmd_output = json.loads(self.openstack('token issue -f json '))
+ cmd_output = self.openstack('token issue', parse_output=True)
auth_project_id = cmd_output['project_id']
- cmd_output = json.loads(self.openstack('project list -f json '))
+ cmd_output = self.openstack('project list', parse_output=True)
admin_project_id = None
demo_project_id = None
for p in cmd_output:
@@ -78,11 +79,12 @@ class RouterTests(common.NetworkTagTests):
name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'router create -f json ' +
+ cmd_output = self.openstack(
+ 'router create ' +
'--disable ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'router delete ' + name1)
self.assertEqual(
@@ -97,11 +99,12 @@ class RouterTests(common.NetworkTagTests):
admin_project_id,
cmd_output["project_id"],
)
- cmd_output = json.loads(self.openstack(
- 'router create -f json ' +
+ cmd_output = self.openstack(
+ 'router create ' +
'--project ' + demo_project_id +
- ' ' + name2
- ))
+ ' ' + name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'router delete ' + name2)
self.assertEqual(
@@ -118,37 +121,41 @@ class RouterTests(common.NetworkTagTests):
)
# Test list --project
- cmd_output = json.loads(self.openstack(
- 'router list -f json ' +
- '--project ' + demo_project_id
- ))
+ cmd_output = self.openstack(
+ 'router list ' +
+ '--project ' + demo_project_id,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
# Test list --disable
- cmd_output = json.loads(self.openstack(
- 'router list -f json ' +
- '--disable '
- ))
+ cmd_output = self.openstack(
+ 'router list ' +
+ '--disable ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
# Test list --name
- cmd_output = json.loads(self.openstack(
- 'router list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'router list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
# Test list --long
- cmd_output = json.loads(self.openstack(
- 'router list -f json ' +
- '--long '
- ))
+ cmd_output = self.openstack(
+ 'router list ' +
+ '--long ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
@@ -160,15 +167,17 @@ class RouterTests(common.NetworkTagTests):
self.skipTest("No l3_agent_scheduler extension present")
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'router create -f json ' + name))
+ cmd_output = self.openstack(
+ 'router create ' + name,
+ parse_output=True,)
self.addCleanup(self.openstack, 'router delete ' + name)
# Get router ID
router_id = cmd_output['id']
# Get l3 agent id
- cmd_output = json.loads(self.openstack(
- 'network agent list -f json --agent-type l3'))
+ cmd_output = self.openstack(
+ 'network agent list --agent-type l3',
+ parse_output=True,)
# Check at least one L3 agent is included in the response.
self.assertTrue(cmd_output)
@@ -178,16 +187,18 @@ class RouterTests(common.NetworkTagTests):
self.openstack(
'network agent add router --l3 ' + agent_id + ' ' + router_id)
- cmd_output = json.loads(self.openstack(
- 'router list -f json --agent ' + agent_id))
+ cmd_output = self.openstack(
+ 'router list --agent ' + agent_id,
+ parse_output=True,)
router_ids = [x['ID'] for x in cmd_output]
self.assertIn(router_id, router_ids)
# Remove router from agent
self.openstack(
'network agent remove router --l3 ' + agent_id + ' ' + router_id)
- cmd_output = json.loads(self.openstack(
- 'router list -f json --agent ' + agent_id))
+ cmd_output = self.openstack(
+ 'router list --agent ' + agent_id,
+ parse_output=True,)
router_ids = [x['ID'] for x in cmd_output]
self.assertNotIn(router_id, router_ids)
@@ -196,11 +207,12 @@ class RouterTests(common.NetworkTagTests):
name = uuid.uuid4().hex
new_name = name + "_"
- cmd_output = json.loads(self.openstack(
- 'router create -f json ' +
+ cmd_output = self.openstack(
+ 'router create ' +
'--description aaaa ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'router delete ' + new_name)
self.assertEqual(
name,
@@ -221,10 +233,11 @@ class RouterTests(common.NetworkTagTests):
)
self.assertOutput('', cmd_output)
- cmd_output = json.loads(self.openstack(
- 'router show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'router show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -247,10 +260,11 @@ class RouterTests(common.NetworkTagTests):
'--external-gateway ' +
new_name
)
- cmd_output = json.loads(self.openstack(
- 'router show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'router show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertIsNone(cmd_output["external_gateway_info"])
def _test_set_router_distributed(self, router_name):
@@ -265,10 +279,11 @@ class RouterTests(common.NetworkTagTests):
)
self.assertOutput('', cmd_output)
- cmd_output = json.loads(self.openstack(
- 'router show -f json ' +
- router_name
- ))
+ cmd_output = self.openstack(
+ 'router show ' +
+ router_name,
+ parse_output=True,
+ )
self.assertTrue(cmd_output["distributed"])
self.assertIsNotNone(cmd_output["external_gateway_info"])
@@ -292,25 +307,28 @@ class RouterTests(common.NetworkTagTests):
self.addCleanup(self.openstack, 'router remove subnet %s %s' % (
router_name, subnet_name))
- out1 = json.loads(self.openstack(
- 'router add route -f json %s '
+ out1 = self.openstack(
+ 'router add route %s '
'--route destination=10.0.10.0/24,gateway=10.0.0.10' %
- router_name)),
+ router_name,
+ parse_output=True,),
self.assertEqual(1, len(out1[0]['routes']))
self.addCleanup(
self.openstack, 'router set %s --no-route' % router_name)
- out2 = json.loads(self.openstack(
- 'router add route -f json %s '
+ out2 = self.openstack(
+ 'router add route %s '
'--route destination=10.0.10.0/24,gateway=10.0.0.10 '
'--route destination=10.0.11.0/24,gateway=10.0.0.11' %
- router_name)),
+ router_name,
+ parse_output=True,),
self.assertEqual(2, len(out2[0]['routes']))
- out3 = json.loads(self.openstack(
- 'router remove route -f json %s '
+ out3 = self.openstack(
+ 'router remove route %s '
'--route destination=10.0.11.0/24,gateway=10.0.0.11 '
'--route destination=10.0.12.0/24,gateway=10.0.0.12' %
- router_name)),
+ router_name,
+ parse_output=True,),
self.assertEqual(1, len(out3[0]['routes']))
diff --git a/openstackclient/tests/functional/network/v2/test_security_group.py b/openstackclient/tests/functional/network/v2/test_security_group.py
index d46f8db7..c9d929f5 100644
--- a/openstackclient/tests/functional/network/v2/test_security_group.py
+++ b/openstackclient/tests/functional/network/v2/test_security_group.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -27,16 +26,17 @@ class SecurityGroupTests(common.NetworkTests):
self.NAME = uuid.uuid4().hex
self.OTHER_NAME = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'security group create -f json ' +
- self.NAME
- ))
+ cmd_output = self.openstack(
+ 'security group create ' +
+ self.NAME,
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'security group delete ' + cmd_output['id'])
self.assertEqual(self.NAME, cmd_output['name'])
def test_security_group_list(self):
- cmd_output = json.loads(self.openstack('security group list -f json'))
+ cmd_output = self.openstack('security group list', parse_output=True)
self.assertIn(self.NAME, [sg['Name'] for sg in cmd_output])
def test_security_group_set(self):
@@ -47,13 +47,17 @@ class SecurityGroupTests(common.NetworkTests):
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'security group show -f json ' + other_name))
+ cmd_output = self.openstack(
+ 'security group show ' + other_name,
+ parse_output=True,
+ )
self.assertEqual('NSA', cmd_output['description'])
self.assertFalse(cmd_output['stateful'])
def test_security_group_show(self):
- cmd_output = json.loads(self.openstack(
- 'security group show -f json ' + self.NAME))
+ cmd_output = self.openstack(
+ 'security group show ' + self.NAME,
+ parse_output=True,
+ )
self.assertEqual(self.NAME, cmd_output['name'])
self.assertTrue(cmd_output['stateful'])
diff --git a/openstackclient/tests/functional/network/v2/test_security_group_rule.py b/openstackclient/tests/functional/network/v2/test_security_group_rule.py
index fe78bf47..d64fb420 100644
--- a/openstackclient/tests/functional/network/v2/test_security_group_rule.py
+++ b/openstackclient/tests/functional/network/v2/test_security_group_rule.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.network.v2 import common
@@ -28,32 +27,38 @@ class SecurityGroupRuleTests(common.NetworkTests):
self.SECURITY_GROUP_NAME = uuid.uuid4().hex
# Create the security group to hold the rule
- cmd_output = json.loads(self.openstack(
- 'security group create -f json ' +
- self.SECURITY_GROUP_NAME
- ))
+ cmd_output = self.openstack(
+ 'security group create ' +
+ self.SECURITY_GROUP_NAME,
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'security group delete ' + self.SECURITY_GROUP_NAME)
self.assertEqual(self.SECURITY_GROUP_NAME, cmd_output['name'])
# Create the security group rule.
- cmd_output = json.loads(self.openstack(
- 'security group rule create -f json ' +
+ cmd_output = self.openstack(
+ 'security group rule create ' +
self.SECURITY_GROUP_NAME + ' ' +
'--protocol tcp --dst-port 80:80 ' +
- '--ingress --ethertype IPv4 '
- ))
+ '--ingress --ethertype IPv4 ',
+ parse_output=True,
+ )
self.addCleanup(self.openstack,
'security group rule delete ' + cmd_output['id'])
self.SECURITY_GROUP_RULE_ID = cmd_output['id']
def test_security_group_rule_list(self):
- cmd_output = json.loads(self.openstack(
- 'security group rule list -f json ' + self.SECURITY_GROUP_NAME))
+ cmd_output = self.openstack(
+ 'security group rule list ' + self.SECURITY_GROUP_NAME,
+ parse_output=True,
+ )
self.assertIn(self.SECURITY_GROUP_RULE_ID,
[rule['ID'] for rule in cmd_output])
def test_security_group_rule_show(self):
- cmd_output = json.loads(self.openstack(
- 'security group rule show -f json ' + self.SECURITY_GROUP_RULE_ID))
+ cmd_output = self.openstack(
+ 'security group rule show ' + self.SECURITY_GROUP_RULE_ID,
+ parse_output=True,
+ )
self.assertEqual(self.SECURITY_GROUP_RULE_ID, cmd_output['id'])
diff --git a/openstackclient/tests/functional/network/v2/test_subnet.py b/openstackclient/tests/functional/network/v2/test_subnet.py
index 38030e01..041ec9f0 100644
--- a/openstackclient/tests/functional/network/v2/test_subnet.py
+++ b/openstackclient/tests/functional/network/v2/test_subnet.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import random
import uuid
@@ -29,10 +28,11 @@ class SubnetTests(common.NetworkTagTests):
cls.NETWORK_NAME = uuid.uuid4().hex
# Create a network for the all subnet tests
- cmd_output = json.loads(cls.openstack(
- 'network create -f json ' +
- cls.NETWORK_NAME
- ))
+ cmd_output = cls.openstack(
+ 'network create ' +
+ cls.NETWORK_NAME,
+ parse_output=True,
+ )
# Get network_id for assertEqual
cls.NETWORK_ID = cmd_output["id"]
@@ -57,7 +57,7 @@ class SubnetTests(common.NetworkTagTests):
def test_subnet_create_and_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd = ('subnet create -f json --network ' +
+ cmd = ('subnet create --network ' +
self.NETWORK_NAME +
' --subnet-range')
cmd_output = self._subnet_create(cmd, name1)
@@ -70,7 +70,7 @@ class SubnetTests(common.NetworkTagTests):
cmd_output["network_id"],
)
name2 = uuid.uuid4().hex
- cmd = ('subnet create -f json --network ' +
+ cmd = ('subnet create --network ' +
self.NETWORK_NAME +
' --subnet-range')
cmd_output = self._subnet_create(cmd, name2)
@@ -91,7 +91,7 @@ class SubnetTests(common.NetworkTagTests):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
name2 = uuid.uuid4().hex
- cmd = ('subnet create -f json ' +
+ cmd = ('subnet create ' +
'--network ' + self.NETWORK_NAME +
' --dhcp --subnet-range')
cmd_output = self._subnet_create(cmd, name1)
@@ -114,7 +114,7 @@ class SubnetTests(common.NetworkTagTests):
cmd_output["ip_version"],
)
- cmd = ('subnet create -f json ' +
+ cmd = ('subnet create ' +
'--network ' + self.NETWORK_NAME +
' --ip-version 6 --no-dhcp ' +
'--subnet-range')
@@ -139,46 +139,51 @@ class SubnetTests(common.NetworkTagTests):
)
# Test list --long
- cmd_output = json.loads(self.openstack(
- 'subnet list -f json ' +
- '--long '
- ))
+ cmd_output = self.openstack(
+ 'subnet list ' +
+ '--long ',
+ parse_output=True,
+ )
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
- ))
+ cmd_output = self.openstack(
+ 'subnet list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
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'
- ))
+ cmd_output = self.openstack(
+ 'subnet list ' +
+ '--ip-version 6',
+ parse_output=True,
+ )
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
- ))
+ cmd_output = self.openstack(
+ 'subnet list ' +
+ '--network ' + self.NETWORK_ID,
+ parse_output=True,
+ )
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 '
- ))
+ cmd_output = self.openstack(
+ 'subnet list ' +
+ '--no-dhcp ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
@@ -188,7 +193,7 @@ class SubnetTests(common.NetworkTagTests):
name = uuid.uuid4().hex
new_name = name + "_"
- cmd = ('subnet create -f json ' +
+ cmd = ('subnet create ' +
'--network ' + self.NETWORK_NAME +
' --description aaaa --subnet-range')
cmd_output = self._subnet_create(cmd, name)
@@ -215,10 +220,11 @@ class SubnetTests(common.NetworkTagTests):
)
self.assertOutput('', cmd_output)
- cmd_output = json.loads(self.openstack(
- 'subnet show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'subnet show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -248,10 +254,11 @@ class SubnetTests(common.NetworkTagTests):
)
self.assertOutput('', cmd_output)
- cmd_output = json.loads(self.openstack(
- 'subnet show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'subnet show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
[],
cmd_output["service_types"],
@@ -274,10 +281,11 @@ class SubnetTests(common.NetworkTagTests):
(hex(random.randint(0, 65535))[2:] for _ in range(7))
)) + ":0/112"
try:
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
cmd + ' ' + subnet + ' ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
except Exception:
if (i == 3):
# raise the exception at the last time
@@ -289,7 +297,7 @@ class SubnetTests(common.NetworkTagTests):
return cmd_output
def _create_resource_for_tag_test(self, name, args):
- cmd = ('subnet create -f json --network ' +
+ cmd = ('subnet create --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 dbcf01e2..8dc5e7a1 100644
--- a/openstackclient/tests/functional/network/v2/test_subnet_pool.py
+++ b/openstackclient/tests/functional/network/v2/test_subnet_pool.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import random
import uuid
@@ -61,10 +60,10 @@ class SubnetPoolTests(common.NetworkTagTests):
def test_subnet_pool_list(self):
"""Test create, list filter"""
- cmd_output = json.loads(self.openstack('token issue -f json'))
+ cmd_output = self.openstack('token issue', parse_output=True)
auth_project_id = cmd_output['project_id']
- cmd_output = json.loads(self.openstack('project list -f json'))
+ cmd_output = self.openstack('project list', parse_output=True)
admin_project_id = None
demo_project_id = None
for p in cmd_output:
@@ -131,37 +130,41 @@ class SubnetPoolTests(common.NetworkTagTests):
)
# Test list --project
- cmd_output = json.loads(self.openstack(
- 'subnet pool list -f json ' +
- '--project ' + demo_project_id
- ))
+ cmd_output = self.openstack(
+ 'subnet pool list ' +
+ '--project ' + demo_project_id,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
# Test list --share
- cmd_output = json.loads(self.openstack(
- 'subnet pool list -f json ' +
- '--share'
- ))
+ cmd_output = self.openstack(
+ 'subnet pool list ' +
+ '--share',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
# Test list --name
- cmd_output = json.loads(self.openstack(
- 'subnet pool list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'subnet pool list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
# Test list --long
- cmd_output = json.loads(self.openstack(
- 'subnet pool list -f json ' +
- '--long '
- ))
+ cmd_output = self.openstack(
+ 'subnet pool list ' +
+ '--long ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
@@ -227,10 +230,11 @@ class SubnetPoolTests(common.NetworkTagTests):
)
self.assertOutput('', cmd_output)
- cmd_output = json.loads(self.openstack(
- 'subnet pool show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'subnet pool show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -307,12 +311,13 @@ class SubnetPoolTests(common.NetworkTagTests):
)) + ":0:0/96"
try:
- cmd_output = json.loads(self.openstack(
- 'subnet pool create -f json ' +
+ cmd_output = self.openstack(
+ 'subnet pool create ' +
cmd + ' ' +
'--pool-prefix ' + pool_prefix + ' ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
except Exception:
if (i == 3):
# Raise the exception the last time
diff --git a/openstackclient/tests/functional/volume/base.py b/openstackclient/tests/functional/volume/base.py
index 53032606..041d8d07 100644
--- a/openstackclient/tests/functional/volume/base.py
+++ b/openstackclient/tests/functional/volume/base.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import time
from openstackclient.tests.functional import base
@@ -27,10 +26,12 @@ class BaseVolumeTests(base.TestCase):
failures = ['error']
total_sleep = 0
while total_sleep < wait:
- output = json.loads(cls.openstack(
- check_type + ' show -f json ' + check_name))
+ output = cls.openstack(
+ check_type + ' show ' + check_name,
+ parse_output=True,
+ )
current_status = output['status']
- if (current_status == desired_status):
+ if current_status == desired_status:
print('{} {} now has status {}'
.format(check_type, check_name, current_status))
return
@@ -51,7 +52,7 @@ class BaseVolumeTests(base.TestCase):
total_sleep = 0
name_field = name_field or 'Name'
while total_sleep < wait:
- result = json.loads(cls.openstack(check_type + ' list -f json'))
+ result = cls.openstack(check_type + ' list', parse_output=True)
names = [x[name_field] for x in result]
if check_name not in names:
print('{} {} is now deleted'.format(check_type, check_name))
diff --git a/openstackclient/tests/functional/volume/v1/test_qos.py b/openstackclient/tests/functional/volume/v1/test_qos.py
index d8277dfc..c449938e 100644
--- a/openstackclient/tests/functional/volume/v1/test_qos.py
+++ b/openstackclient/tests/functional/volume/v1/test_qos.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v1 import common
@@ -22,29 +21,32 @@ class QosTests(common.BaseVolumeTests):
def test_volume_qos_create_list(self):
"""Test create, list, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name']
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name']
)
# Test list
- cmd_output = json.loads(self.openstack(
- 'volume qos list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume qos list',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
@@ -57,12 +59,13 @@ class QosTests(common.BaseVolumeTests):
"""Tests create volume qos, set, unset, show, delete"""
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
+ cmd_output = self.openstack(
+ 'volume qos create ' +
'--consumer front-end '
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume qos delete ' + name)
self.assertEqual(
name,
@@ -84,10 +87,11 @@ class QosTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test volume qos show
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -105,10 +109,11 @@ class QosTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
diff --git a/openstackclient/tests/functional/volume/v1/test_service.py b/openstackclient/tests/functional/volume/v1/test_service.py
index fee73f18..7de2de55 100644
--- a/openstackclient/tests/functional/volume/v1/test_service.py
+++ b/openstackclient/tests/functional/volume/v1/test_service.py
@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from openstackclient.tests.functional.volume.v1 import common
@@ -19,18 +17,18 @@ class VolumeServiceTests(common.BaseVolumeTests):
"""Functional tests for volume service."""
def test_volume_service_list(self):
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json'))
+ cmd_output = self.openstack('volume service list', parse_output=True)
# Get the nonredundant services and hosts
services = list(set([x['Binary'] for x in cmd_output]))
# Test volume service list --service
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json ' +
+ cmd_output = self.openstack(
+ 'volume service list ' +
'--service ' +
- services[0]
- ))
+ services[0],
+ parse_output=True,
+ )
for x in cmd_output:
self.assertEqual(
services[0],
@@ -43,9 +41,10 @@ class VolumeServiceTests(common.BaseVolumeTests):
def test_volume_service_set(self):
# Get a service and host
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume service list',
+ parse_output=True,
+ )
service_1 = cmd_output[0]['Binary']
host_1 = cmd_output[0]['Host']
@@ -57,9 +56,10 @@ class VolumeServiceTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json --long'
- ))
+ cmd_output = self.openstack(
+ 'volume service list --long',
+ parse_output=True,
+ )
self.assertEqual(
'enabled',
cmd_output[0]['Status']
@@ -77,9 +77,10 @@ class VolumeServiceTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json --long'
- ))
+ cmd_output = self.openstack(
+ 'volume service list --long',
+ parse_output=True,
+ )
self.assertEqual(
'disabled',
cmd_output[0]['Status']
diff --git a/openstackclient/tests/functional/volume/v1/test_snapshot.py b/openstackclient/tests/functional/volume/v1/test_snapshot.py
index 5a76a2e9..c8c956d1 100644
--- a/openstackclient/tests/functional/volume/v1/test_snapshot.py
+++ b/openstackclient/tests/functional/volume/v1/test_snapshot.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v1 import common
@@ -25,11 +24,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def setUpClass(cls):
super(VolumeSnapshotTests, cls).setUpClass()
# create a volume for all tests to create snapshot
- cmd_output = json.loads(cls.openstack(
- 'volume create -f json ' +
+ cmd_output = cls.openstack(
+ 'volume create ' +
'--size 1 ' +
- cls.VOLLY
- ))
+ cls.VOLLY,
+ parse_output=True,
+ )
cls.wait_for_status('volume', cls.VOLLY, 'available')
cls.VOLUME_ID = cmd_output['id']
@@ -45,22 +45,24 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def test_volume_snapshot_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name1 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output["display_name"],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name2 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output["display_name"],
@@ -78,11 +80,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def test_volume_snapshot_list(self):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name1 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', name1)
self.addCleanup(self.openstack, 'volume snapshot delete ' + name1)
self.assertEqual(
@@ -100,11 +103,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.wait_for_status('volume snapshot', name1, 'available')
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name2 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', name2)
self.addCleanup(self.openstack, 'volume snapshot delete ' + name2)
self.assertEqual(
@@ -122,29 +126,32 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.wait_for_status('volume snapshot', name2, 'available')
# Test list --long, --status
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
'--long ' +
- '--status error'
- ))
+ '--status error',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertNotIn(name2, names)
# Test list --volume
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
- '--volume ' + self.VOLLY
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
+ '--volume ' + self.VOLLY,
+ parse_output=True,
+ )
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(
- 'volume snapshot list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
@@ -153,12 +160,13 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
"""Test create, set, unset, show, delete volume snapshot"""
name = uuid.uuid4().hex
new_name = name + "_"
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
'--volume ' + self.VOLLY +
' --description aaaa ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name)
self.addCleanup(self.openstack, 'volume snapshot delete ' + new_name)
self.assertEqual(
@@ -187,10 +195,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Show snapshot set result
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["display_name"],
@@ -216,10 +225,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
{'Beta': 'b'},
cmd_output["properties"],
@@ -232,8 +242,9 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
new_name,
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output["properties"])
diff --git a/openstackclient/tests/functional/volume/v1/test_transfer_request.py b/openstackclient/tests/functional/volume/v1/test_transfer_request.py
index 0399e6cc..0ee73d8a 100644
--- a/openstackclient/tests/functional/volume/v1/test_transfer_request.py
+++ b/openstackclient/tests/functional/volume/v1/test_transfer_request.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v1 import common
@@ -25,8 +24,10 @@ class TransferRequestTests(common.BaseVolumeTests):
@classmethod
def setUpClass(cls):
super(TransferRequestTests, cls).setUpClass()
- cmd_output = json.loads(cls.openstack(
- 'volume create -f json --size 1 ' + cls.VOLUME_NAME))
+ cmd_output = cls.openstack(
+ 'volume create --size 1 ' + cls.VOLUME_NAME,
+ parse_output=True,
+ )
cls.assertOutput(cls.VOLUME_NAME, cmd_output['name'])
cls.wait_for_status("volume", cls.VOLUME_NAME, "available")
@@ -45,26 +46,31 @@ class TransferRequestTests(common.BaseVolumeTests):
name = uuid.uuid4().hex
# create a volume
- cmd_output = json.loads(self.openstack(
- 'volume create -f json --size 1 ' + volume_name))
+ cmd_output = self.openstack(
+ 'volume create --size 1 ' + volume_name,
+ parse_output=True,
+ )
self.assertEqual(volume_name, cmd_output['name'])
# create volume transfer request for the volume
# and get the auth_key of the new transfer request
- cmd_output = json.loads(self.openstack(
- 'volume transfer request create -f json ' +
+ cmd_output = self.openstack(
+ 'volume transfer request create ' +
volume_name +
- ' --name ' + name))
+ ' --name ' + name,
+ parse_output=True,
+ )
auth_key = cmd_output['auth_key']
self.assertTrue(auth_key)
# accept the volume transfer request
- json_output = json.loads(self.openstack(
- 'volume transfer request accept -f json ' +
+ output = self.openstack(
+ 'volume transfer request accept ' +
name + ' ' +
- '--auth-key ' + auth_key
- ))
- self.assertEqual(name, json_output.get('name'))
+ '--auth-key ' + auth_key,
+ parse_output=True,
+ )
+ self.assertEqual(name, output.get('name'))
# the volume transfer will be removed by default after accepted
# so just need to delete the volume here
@@ -74,11 +80,12 @@ class TransferRequestTests(common.BaseVolumeTests):
def test_volume_transfer_request_list_show(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume transfer request create -f json ' +
+ cmd_output = self.openstack(
+ 'volume transfer request create ' +
' --name ' + name + ' ' +
- self.VOLUME_NAME
- ))
+ self.VOLUME_NAME,
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume transfer request delete ' + name
@@ -87,13 +94,15 @@ class TransferRequestTests(common.BaseVolumeTests):
auth_key = cmd_output['auth_key']
self.assertTrue(auth_key)
- cmd_output = json.loads(self.openstack(
- 'volume transfer request list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume transfer request list',
+ parse_output=True,
+ )
self.assertIn(name, [req['Name'] for req in cmd_output])
- cmd_output = json.loads(self.openstack(
- 'volume transfer request show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume transfer request show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(name, cmd_output['name'])
diff --git a/openstackclient/tests/functional/volume/v1/test_volume.py b/openstackclient/tests/functional/volume/v1/test_volume.py
index 013bc6a4..727ee73b 100644
--- a/openstackclient/tests/functional/volume/v1/test_volume.py
+++ b/openstackclient/tests/functional/volume/v1/test_volume.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v1 import common
@@ -22,22 +21,24 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_create_and_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
1,
cmd_output["size"],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 2 ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
2,
cmd_output["size"],
@@ -51,11 +52,12 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_list(self):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name1)
self.assertEqual(
1,
@@ -64,11 +66,12 @@ class VolumeTests(common.BaseVolumeTests):
self.wait_for_status("volume", name1, "available")
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 2 ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name2)
self.assertEqual(
2,
@@ -77,25 +80,28 @@ class VolumeTests(common.BaseVolumeTests):
self.wait_for_status("volume", name2, "available")
# Test list
- cmd_output = json.loads(self.openstack(
- 'volume list -f json '
- ))
+ cmd_output = self.openstack(
+ 'volume list ',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
# Test list --long
- cmd_output = json.loads(self.openstack(
- 'volume list -f json --long'
- ))
+ cmd_output = self.openstack(
+ 'volume list --long',
+ parse_output=True,
+ )
bootable = [x["Bootable"] for x in cmd_output]
self.assertIn('false', bootable)
# Test list --name
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'volume list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
@@ -103,13 +109,14 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_set_and_unset(self):
"""Tests create volume, set, unset, show, delete"""
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
'--description aaaa ' +
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output["name"],
@@ -148,10 +155,11 @@ class VolumeTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -181,10 +189,11 @@ class VolumeTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
{'Gamma': 'c'},
cmd_output["properties"],
@@ -193,42 +202,46 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_create_and_list_and_show_backward_compatibility(self):
"""Test backward compatibility of create, list, show"""
name1 = uuid.uuid4().hex
- json_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ output = self.openstack(
+ 'volume create ' +
'-c display_name -c id ' +
'--size 1 ' +
- name1
- ))
- self.assertIn('display_name', json_output)
- self.assertEqual(name1, json_output['display_name'])
- self.assertIn('id', json_output)
- volume_id = json_output['id']
+ name1,
+ parse_output=True,
+ )
+ self.assertIn('display_name', output)
+ self.assertEqual(name1, output['display_name'])
+ self.assertIn('id', output)
+ volume_id = output['id']
self.assertIsNotNone(volume_id)
- self.assertNotIn('name', json_output)
+ self.assertNotIn('name', output)
self.addCleanup(self.openstack, 'volume delete ' + volume_id)
self.wait_for_status("volume", name1, "available")
- json_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '-c "Display Name"'
- ))
- for each_volume in json_output:
+ output = self.openstack(
+ 'volume list ' +
+ '-c "Display Name"',
+ parse_output=True,
+ )
+ for each_volume in output:
self.assertIn('Display Name', each_volume)
- json_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '-c "Name"'
- ))
- for each_volume in json_output:
+ output = self.openstack(
+ 'volume list ' +
+ '-c "Name"',
+ parse_output=True,
+ )
+ for each_volume in output:
self.assertIn('Name', each_volume)
- json_output = json.loads(self.openstack(
- 'volume show -f json ' +
+ output = self.openstack(
+ 'volume show ' +
'-c display_name -c id ' +
- name1
- ))
- self.assertIn('display_name', json_output)
- self.assertEqual(name1, json_output['display_name'])
- self.assertIn('id', json_output)
- self.assertNotIn('name', json_output)
+ name1,
+ parse_output=True,
+ )
+ self.assertIn('display_name', output)
+ self.assertEqual(name1, output['display_name'])
+ self.assertIn('id', output)
+ self.assertNotIn('name', output)
diff --git a/openstackclient/tests/functional/volume/v1/test_volume_type.py b/openstackclient/tests/functional/volume/v1/test_volume_type.py
index 7434b5b3..037d45f0 100644
--- a/openstackclient/tests/functional/volume/v1/test_volume_type.py
+++ b/openstackclient/tests/functional/volume/v1/test_volume_type.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import time
import uuid
@@ -22,10 +21,11 @@ class VolumeTypeTests(common.BaseVolumeTests):
def test_volume_type_create_list(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' +
@@ -33,26 +33,29 @@ class VolumeTypeTests(common.BaseVolumeTests):
)
self.assertEqual(name, cmd_output['name'])
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual(self.NAME, cmd_output['name'])
- cmd_output = json.loads(self.openstack('volume type list -f json'))
+ cmd_output = self.openstack('volume type list', parse_output=True)
self.assertIn(self.NAME, [t['Name'] for t in cmd_output])
- cmd_output = json.loads(self.openstack(
- 'volume type list -f json --default'
- ))
+ cmd_output = self.openstack(
+ 'volume type list --default',
+ parse_output=True,
+ )
self.assertEqual(1, len(cmd_output))
self.assertEqual('lvmdriver-1', cmd_output[0]['Name'])
def test_volume_type_set_unset_properties(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -63,26 +66,29 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type set --property a=b --property c=d %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
raw_output = self.openstack(
'volume type unset --property a %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'c': 'd'}, cmd_output['properties'])
def test_volume_type_set_unset_multiple_properties(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -93,18 +99,20 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type set --property a=b --property c=d %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
raw_output = self.openstack(
'volume type unset --property a --property c %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output['properties'])
def test_multi_delete(self):
@@ -125,13 +133,13 @@ class VolumeTypeTests(common.BaseVolumeTests):
def test_encryption_type(self):
encryption_type = uuid.uuid4().hex
# test create new encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json '
+ cmd_output = self.openstack(
+ 'volume type create '
'--encryption-provider LuksEncryptor '
'--encryption-cipher aes-xts-plain64 '
'--encryption-key-size 128 '
'--encryption-control-location front-end ' +
- encryption_type))
+ encryption_type)
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -139,8 +147,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test show encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + encryption_type))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -148,8 +158,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test list encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type list -f json --encryption-type'))
+ cmd_output = self.openstack(
+ 'volume type list --encryption-type',
+ parse_output=True,
+ )
encryption_output = [t['Encryption'] for t in cmd_output
if t['Name'] == encryption_type][0]
expected = {'provider': 'LuksEncryptor',
@@ -169,19 +181,20 @@ class VolumeTypeTests(common.BaseVolumeTests):
self.assertEqual('', raw_output)
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
- name,
- ))
+ cmd_output = self.openstack(
+ 'volume type create --private ' + name,
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name,
)
self.assertEqual(name, cmd_output['name'])
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + name
- ))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + name,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -193,9 +206,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type unset --encryption-type ' + name
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + name
- ))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output['encryption'])
# test delete encryption type
raw_output = self.openstack('volume type delete ' + encryption_type)
diff --git a/openstackclient/tests/functional/volume/v2/test_qos.py b/openstackclient/tests/functional/volume/v2/test_qos.py
index f9f6e099..0a540573 100644
--- a/openstackclient/tests/functional/volume/v2/test_qos.py
+++ b/openstackclient/tests/functional/volume/v2/test_qos.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v2 import common
@@ -22,29 +21,32 @@ class QosTests(common.BaseVolumeTests):
def test_volume_qos_create_delete_list(self):
"""Test create, list, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name']
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name']
)
# Test list
- cmd_output = json.loads(self.openstack(
- 'volume qos list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume qos list',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
@@ -57,12 +59,13 @@ class QosTests(common.BaseVolumeTests):
"""Tests create volume qos, set, unset, show, delete"""
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
+ cmd_output = self.openstack(
+ 'volume qos create ' +
'--consumer front-end '
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume qos delete ' + name)
self.assertEqual(
name,
@@ -88,10 +91,11 @@ class QosTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test volume qos show
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -109,10 +113,11 @@ class QosTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -125,10 +130,11 @@ class QosTests(common.BaseVolumeTests):
def test_volume_qos_asso_disasso(self):
"""Tests associate and disassociate qos with volume type"""
vol_type1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json ' +
- vol_type1
- ))
+ cmd_output = self.openstack(
+ 'volume type create ' +
+ vol_type1,
+ parse_output=True,
+ )
self.assertEqual(
vol_type1,
cmd_output['name']
@@ -136,10 +142,11 @@ class QosTests(common.BaseVolumeTests):
self.addCleanup(self.openstack, 'volume type delete ' + vol_type1)
vol_type2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json ' +
- vol_type2
- ))
+ cmd_output = self.openstack(
+ 'volume type create ' +
+ vol_type2,
+ parse_output=True,
+ )
self.assertEqual(
vol_type2,
cmd_output['name']
@@ -147,10 +154,11 @@ class QosTests(common.BaseVolumeTests):
self.addCleanup(self.openstack, 'volume type delete ' + vol_type2)
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -169,10 +177,11 @@ class QosTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
types = cmd_output["associations"]
self.assertIn(vol_type1, types)
self.assertIn(vol_type2, types)
@@ -184,10 +193,11 @@ class QosTests(common.BaseVolumeTests):
' ' + name
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
types = cmd_output["associations"]
self.assertNotIn(vol_type1, types)
self.assertIn(vol_type2, types)
@@ -198,10 +208,11 @@ class QosTests(common.BaseVolumeTests):
name + ' ' + vol_type1
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
types = cmd_output["associations"]
self.assertIn(vol_type1, types)
self.assertIn(vol_type2, types)
@@ -211,8 +222,9 @@ class QosTests(common.BaseVolumeTests):
'--all ' + name
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertNotIn("associations", cmd_output.keys())
diff --git a/openstackclient/tests/functional/volume/v2/test_service.py b/openstackclient/tests/functional/volume/v2/test_service.py
index 7ec43fe8..5794f81f 100644
--- a/openstackclient/tests/functional/volume/v2/test_service.py
+++ b/openstackclient/tests/functional/volume/v2/test_service.py
@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from openstackclient.tests.functional.volume.v2 import common
@@ -19,19 +17,19 @@ class VolumeServiceTests(common.BaseVolumeTests):
"""Functional tests for volume service."""
def test_volume_service_list(self):
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json'))
+ cmd_output = self.openstack('volume service list', parse_output=True)
# Get the nonredundant services and hosts
services = list(set([x['Binary'] for x in cmd_output]))
hosts = list(set([x['Host'] for x in cmd_output]))
# Test volume service list --service
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json ' +
+ cmd_output = self.openstack(
+ 'volume service list ' +
'--service ' +
- services[0]
- ))
+ services[0],
+ parse_output=True,
+ )
for x in cmd_output:
self.assertEqual(
services[0],
@@ -39,11 +37,12 @@ class VolumeServiceTests(common.BaseVolumeTests):
)
# Test volume service list --host
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json ' +
+ cmd_output = self.openstack(
+ 'volume service list ' +
'--host ' +
- hosts[0]
- ))
+ hosts[0],
+ parse_output=True,
+ )
for x in cmd_output:
self.assertIn(
hosts[0],
@@ -53,9 +52,10 @@ class VolumeServiceTests(common.BaseVolumeTests):
def test_volume_service_set(self):
# Get a service and host
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume service list',
+ parse_output=True,
+ )
service_1 = cmd_output[0]['Binary']
host_1 = cmd_output[0]['Host']
@@ -67,9 +67,10 @@ class VolumeServiceTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json --long'
- ))
+ cmd_output = self.openstack(
+ 'volume service list --long',
+ parse_output=True,
+ )
self.assertEqual(
'enabled',
cmd_output[0]['Status']
@@ -89,9 +90,10 @@ class VolumeServiceTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume service list -f json --long'
- ))
+ cmd_output = self.openstack(
+ 'volume service list --long',
+ parse_output=True,
+ )
self.assertEqual(
'disabled',
cmd_output[0]['Status']
diff --git a/openstackclient/tests/functional/volume/v2/test_transfer_request.py b/openstackclient/tests/functional/volume/v2/test_transfer_request.py
index 00d0865c..ac71cba2 100644
--- a/openstackclient/tests/functional/volume/v2/test_transfer_request.py
+++ b/openstackclient/tests/functional/volume/v2/test_transfer_request.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v2 import common
@@ -26,11 +25,12 @@ class TransferRequestTests(common.BaseVolumeTests):
xfer_name = uuid.uuid4().hex
# create a volume
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertEqual(volume_name, cmd_output['name'])
self.addCleanup(
self.openstack,
@@ -42,12 +42,13 @@ class TransferRequestTests(common.BaseVolumeTests):
# create volume transfer request for the volume
# and get the auth_key of the new transfer request
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request create -f json ' +
+ 'volume transfer request create ' +
' --name ' + xfer_name + ' ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
xfer_id = cmd_output['id']
auth_key = cmd_output['auth_key']
@@ -55,12 +56,13 @@ class TransferRequestTests(common.BaseVolumeTests):
self.wait_for_status("volume", volume_name, "awaiting-transfer")
# accept the volume transfer request
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request accept -f json ' +
+ 'volume transfer request accept ' +
'--auth-key ' + auth_key + ' ' +
- xfer_id
- ))
+ xfer_id,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
self.wait_for_status("volume", volume_name, "available")
@@ -69,11 +71,12 @@ class TransferRequestTests(common.BaseVolumeTests):
xfer_name = uuid.uuid4().hex
# create a volume
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertEqual(volume_name, cmd_output['name'])
self.addCleanup(
self.openstack,
@@ -83,29 +86,32 @@ class TransferRequestTests(common.BaseVolumeTests):
)
self.wait_for_status("volume", volume_name, "available")
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request create -f json ' +
+ 'volume transfer request create ' +
' --name ' + xfer_name + ' ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
xfer_id = cmd_output['id']
auth_key = cmd_output['auth_key']
self.assertTrue(auth_key)
self.wait_for_status("volume", volume_name, "awaiting-transfer")
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request list -f json'
- ))
+ 'volume transfer request list',
+ parse_output=True,
+ )
self.assertIn(xfer_name, [req['Name'] for req in cmd_output])
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request show -f json ' +
- xfer_id
- ))
+ 'volume transfer request show ' +
+ xfer_id,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
# NOTE(dtroyer): We need to delete the transfer request to allow the
diff --git a/openstackclient/tests/functional/volume/v2/test_volume.py b/openstackclient/tests/functional/volume/v2/test_volume.py
index 19fd5895..832dabe6 100644
--- a/openstackclient/tests/functional/volume/v2/test_volume.py
+++ b/openstackclient/tests/functional/volume/v2/test_volume.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v2 import common
@@ -22,22 +21,24 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
1,
cmd_output["size"],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 2 ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
2,
cmd_output["size"],
@@ -51,11 +52,12 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_list(self):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name1)
self.assertEqual(
1,
@@ -64,11 +66,12 @@ class VolumeTests(common.BaseVolumeTests):
self.wait_for_status("volume", name1, "available")
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 2 ' +
- name2
- ))
+ name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name2)
self.assertEqual(
2,
@@ -83,19 +86,21 @@ class VolumeTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test list --long
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '--long'
- ))
+ cmd_output = self.openstack(
+ 'volume list ' +
+ '--long',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
# Test list --status
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '--status error'
- ))
+ cmd_output = self.openstack(
+ 'volume list ' +
+ '--status error',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
@@ -107,13 +112,14 @@ class VolumeTests(common.BaseVolumeTests):
"""Tests create volume, set, unset, show, delete"""
name = uuid.uuid4().hex
new_name = name + "_"
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
'--description aaaa ' +
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + new_name)
self.assertEqual(
name,
@@ -153,10 +159,11 @@ class VolumeTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -191,10 +198,11 @@ class VolumeTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
{'Gamma': 'c'},
cmd_output["properties"],
@@ -210,30 +218,33 @@ class VolumeTests(common.BaseVolumeTests):
volume_name = uuid.uuid4().hex
snapshot_name = uuid.uuid4().hex
# Make a snapshot
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.wait_for_status("volume", volume_name, "available")
self.assertEqual(
volume_name,
cmd_output["name"],
)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
snapshot_name +
- ' --volume ' + volume_name
- ))
+ ' --volume ' + volume_name,
+ parse_output=True,
+ )
self.wait_for_status("volume snapshot", snapshot_name, "available")
name = uuid.uuid4().hex
# Create volume from snapshot
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--snapshot ' + snapshot_name +
- ' ' + name
- ))
+ ' ' + name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name)
self.addCleanup(self.openstack, 'volume delete ' + volume_name)
self.assertEqual(
@@ -253,11 +264,12 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_list_backward_compatibility(self):
"""Test backward compatibility of list command"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- name1
- ))
+ name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name1)
self.assertEqual(
1,
@@ -266,17 +278,19 @@ class VolumeTests(common.BaseVolumeTests):
self.wait_for_status("volume", name1, "available")
# Test list -c "Display Name"
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '-c "Display Name"'
- ))
+ cmd_output = self.openstack(
+ 'volume list ' +
+ '-c "Display Name"',
+ parse_output=True,
+ )
for each_volume in cmd_output:
self.assertIn('Display Name', each_volume)
# Test list -c "Name"
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '-c "Name"'
- ))
+ cmd_output = self.openstack(
+ 'volume list ' +
+ '-c "Name"',
+ parse_output=True,
+ )
for each_volume in cmd_output:
self.assertIn('Name', each_volume)
diff --git a/openstackclient/tests/functional/volume/v2/test_volume_backup.py b/openstackclient/tests/functional/volume/v2/test_volume_backup.py
index 6868bd40..07bd2d16 100644
--- a/openstackclient/tests/functional/volume/v2/test_volume_backup.py
+++ b/openstackclient/tests/functional/volume/v2/test_volume_backup.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v2 import common
@@ -22,7 +21,7 @@ class VolumeBackupTests(common.BaseVolumeTests):
def setUp(self):
super(VolumeBackupTests, self).setUp()
self.backup_enabled = False
- serv_list = json.loads(self.openstack('volume service list -f json'))
+ serv_list = self.openstack('volume service list', parse_output=True)
for service in serv_list:
if service['Binary'] == 'cinder-backup':
if service['Status'] == 'enabled':
@@ -34,24 +33,28 @@ class VolumeBackupTests(common.BaseVolumeTests):
self.skipTest('Backup service is not enabled')
vol_id = uuid.uuid4().hex
# create a volume
- json.loads(self.openstack(
- 'volume create -f json ' +
+ self.openstack(
+ 'volume create ' +
'--size 1 ' +
- vol_id
- ))
+ vol_id,
+ parse_output=True,
+ )
self.wait_for_status("volume", vol_id, "available")
# create a backup
- backup = json.loads(self.openstack(
- 'volume backup create -f json ' +
- vol_id
- ))
+ backup = self.openstack(
+ 'volume backup create ' +
+ vol_id,
+ parse_output=True,
+ )
self.wait_for_status("volume backup", backup['id'], "available")
# restore the backup
- backup_restored = json.loads(self.openstack(
- 'volume backup restore -f json %s %s'
- % (backup['id'], vol_id)))
+ backup_restored = self.openstack(
+ 'volume backup restore %s %s'
+ % (backup['id'], vol_id),
+ parse_output=True,
+ )
self.assertEqual(backup_restored['backup_id'], backup['id'])
self.wait_for_status("volume backup", backup['id'], "available")
self.wait_for_status("volume", backup_restored['volume_id'],
diff --git a/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py b/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py
index 4977a73e..12fdad2c 100644
--- a/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py
+++ b/openstackclient/tests/functional/volume/v2/test_volume_snapshot.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v2 import common
@@ -25,11 +24,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def setUpClass(cls):
super(VolumeSnapshotTests, cls).setUpClass()
# create a volume for all tests to create snapshot
- cmd_output = json.loads(cls.openstack(
- 'volume create -f json ' +
+ cmd_output = cls.openstack(
+ 'volume create ' +
'--size 1 ' +
- cls.VOLLY
- ))
+ cls.VOLLY,
+ parse_output=True,
+ )
cls.wait_for_status('volume', cls.VOLLY, 'available')
cls.VOLUME_ID = cmd_output['id']
@@ -46,22 +46,24 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def test_volume_snapshot_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name1 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output["name"],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name2 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output["name"],
@@ -79,11 +81,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def test_volume_snapshot_list(self):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name1 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', name1)
self.addCleanup(self.openstack, 'volume snapshot delete ' + name1)
self.assertEqual(
@@ -101,11 +104,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.wait_for_status('volume snapshot', name1, 'available')
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name2 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', name2)
self.addCleanup(self.openstack, 'volume snapshot delete ' + name2)
self.assertEqual(
@@ -130,11 +134,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test list --long, --status
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
'--long ' +
- '--status error_deleting'
- ))
+ '--status error_deleting',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
@@ -147,29 +152,32 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test list --long, --status
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
'--long ' +
- '--status error'
- ))
+ '--status error',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
# Test list --volume
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
- '--volume ' + self.VOLLY
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
+ '--volume ' + self.VOLLY,
+ parse_output=True,
+ )
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(
- 'volume snapshot list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
@@ -178,13 +186,14 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
"""Test create, set, unset, show, delete volume snapshot"""
name = uuid.uuid4().hex
new_name = name + "_"
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
'--volume ' + self.VOLLY +
' --description aaaa ' +
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name)
self.addCleanup(self.openstack, 'volume snapshot delete ' + new_name)
self.assertEqual(
@@ -217,10 +226,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Show snapshot set result
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -246,10 +256,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
{'Beta': 'b'},
cmd_output["properties"],
@@ -262,10 +273,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
new_name,
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertNotIn(
{'Beta': 'b'},
cmd_output["properties"],
diff --git a/openstackclient/tests/functional/volume/v2/test_volume_type.py b/openstackclient/tests/functional/volume/v2/test_volume_type.py
index 861c393d..5cad9297 100644
--- a/openstackclient/tests/functional/volume/v2/test_volume_type.py
+++ b/openstackclient/tests/functional/volume/v2/test_volume_type.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import time
import uuid
@@ -22,36 +21,40 @@ class VolumeTypeTests(common.BaseVolumeTests):
def test_volume_type_create_list(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name,
)
self.assertEqual(name, cmd_output['name'])
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual(name, cmd_output['name'])
- cmd_output = json.loads(self.openstack('volume type list -f json'))
+ cmd_output = self.openstack('volume type list', parse_output=True)
self.assertIn(name, [t['Name'] for t in cmd_output])
- cmd_output = json.loads(self.openstack(
- 'volume type list -f json --default'
- ))
+ cmd_output = self.openstack(
+ 'volume type list --default',
+ parse_output=True,
+ )
self.assertEqual(1, len(cmd_output))
self.assertEqual('lvmdriver-1', cmd_output[0]['Name'])
def test_volume_type_set_unset_properties(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -62,26 +65,29 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type set --property a=b --property c=d %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
raw_output = self.openstack(
'volume type unset --property a %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'c': 'd'}, cmd_output['properties'])
def test_volume_type_set_unset_multiple_properties(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -92,26 +98,29 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type set --property a=b --property c=d %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
raw_output = self.openstack(
'volume type unset --property a --property c %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output['properties'])
def test_volume_type_set_unset_project(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -147,13 +156,15 @@ class VolumeTypeTests(common.BaseVolumeTests):
name = uuid.uuid4().hex
encryption_type = uuid.uuid4().hex
# test create new encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json '
+ cmd_output = self.openstack(
+ 'volume type create '
'--encryption-provider LuksEncryptor '
'--encryption-cipher aes-xts-plain64 '
'--encryption-key-size 128 '
'--encryption-control-location front-end ' +
- encryption_type))
+ encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -161,8 +172,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test show encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + encryption_type))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -170,8 +183,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test list encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type list -f json --encryption-type'))
+ cmd_output = self.openstack(
+ 'volume type list --encryption-type',
+ parse_output=True,
+ )
encryption_output = [t['Encryption'] for t in cmd_output
if t['Name'] == encryption_type][0]
expected = {'provider': 'LuksEncryptor',
@@ -187,8 +202,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
'--encryption-control-location back-end ' +
encryption_type)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + encryption_type))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 256,
@@ -196,10 +213,11 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test set new encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name,
@@ -215,9 +233,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
name)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + name
- ))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + name,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -229,9 +248,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type unset --encryption-type ' + name
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + name
- ))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output['encryption'])
# test delete encryption type
raw_output = self.openstack('volume type delete ' + encryption_type)
diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py
index fdfa6827..51578e14 100644
--- a/openstackclient/tests/functional/volume/v3/test_qos.py
+++ b/openstackclient/tests/functional/volume/v3/test_qos.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v3 import common
@@ -22,29 +21,32 @@ class QosTests(common.BaseVolumeTests):
def test_volume_qos_create_delete_list(self):
"""Test create, list, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name1,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output['name']
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name2,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output['name']
)
# Test list
- cmd_output = json.loads(self.openstack(
- 'volume qos list -f json'
- ))
+ cmd_output = self.openstack(
+ 'volume qos list',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
@@ -57,12 +59,13 @@ class QosTests(common.BaseVolumeTests):
"""Tests create volume qos, set, unset, show, delete"""
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
+ cmd_output = self.openstack(
+ 'volume qos create ' +
'--consumer front-end '
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume qos delete ' + name)
self.assertEqual(
name,
@@ -88,10 +91,11 @@ class QosTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test volume qos show
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -109,10 +113,11 @@ class QosTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -125,10 +130,11 @@ class QosTests(common.BaseVolumeTests):
def test_volume_qos_asso_disasso(self):
"""Tests associate and disassociate qos with volume type"""
vol_type1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json ' +
- vol_type1
- ))
+ cmd_output = self.openstack(
+ 'volume type create ' +
+ vol_type1,
+ parse_output=True,
+ )
self.assertEqual(
vol_type1,
cmd_output['name']
@@ -136,10 +142,11 @@ class QosTests(common.BaseVolumeTests):
self.addCleanup(self.openstack, 'volume type delete ' + vol_type1)
vol_type2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json ' +
- vol_type2
- ))
+ cmd_output = self.openstack(
+ 'volume type create ' +
+ vol_type2,
+ parse_output=True,
+ )
self.assertEqual(
vol_type2,
cmd_output['name']
@@ -147,10 +154,11 @@ class QosTests(common.BaseVolumeTests):
self.addCleanup(self.openstack, 'volume type delete ' + vol_type2)
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume qos create -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos create ' +
+ name,
+ parse_output=True,
+ )
self.assertEqual(
name,
cmd_output['name']
@@ -169,10 +177,11 @@ class QosTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
types = cmd_output["associations"]
self.assertIn(vol_type1, types)
self.assertIn(vol_type2, types)
@@ -184,10 +193,11 @@ class QosTests(common.BaseVolumeTests):
' ' + name
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
types = cmd_output["associations"]
self.assertNotIn(vol_type1, types)
self.assertIn(vol_type2, types)
@@ -198,10 +208,11 @@ class QosTests(common.BaseVolumeTests):
name + ' ' + vol_type1
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
types = cmd_output["associations"]
self.assertIn(vol_type1, types)
self.assertIn(vol_type2, types)
@@ -211,8 +222,9 @@ class QosTests(common.BaseVolumeTests):
'--all ' + name
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume qos show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'volume qos show ' +
+ name,
+ parse_output=True,
+ )
self.assertNotIn("associations", cmd_output.keys())
diff --git a/openstackclient/tests/functional/volume/v3/test_transfer_request.py b/openstackclient/tests/functional/volume/v3/test_transfer_request.py
index 1bbfedc9..449fa08e 100644
--- a/openstackclient/tests/functional/volume/v3/test_transfer_request.py
+++ b/openstackclient/tests/functional/volume/v3/test_transfer_request.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v3 import common
@@ -26,11 +25,12 @@ class TransferRequestTests(common.BaseVolumeTests):
xfer_name = uuid.uuid4().hex
# create a volume
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
- volume_name
- ))
+ volume_name,
+ parse_output=True,
+ )
self.assertEqual(volume_name, cmd_output['name'])
self.addCleanup(
self.openstack,
@@ -42,12 +42,12 @@ class TransferRequestTests(common.BaseVolumeTests):
# create volume transfer request for the volume
# and get the auth_key of the new transfer request
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request create -f json ' +
- ' --name ' + xfer_name + ' ' +
- volume_name
- ))
+ 'volume transfer request create ' +
+ ' --name ' + xfer_name + ' ' + volume_name,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
xfer_id = cmd_output['id']
auth_key = cmd_output['auth_key']
@@ -55,12 +55,12 @@ class TransferRequestTests(common.BaseVolumeTests):
self.wait_for_status("volume", volume_name, "awaiting-transfer")
# accept the volume transfer request
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request accept -f json ' +
- '--auth-key ' + auth_key + ' ' +
- xfer_id
- ))
+ 'volume transfer request accept ' +
+ '--auth-key ' + auth_key + ' ' + xfer_id,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
self.wait_for_status("volume", volume_name, "available")
@@ -69,11 +69,11 @@ class TransferRequestTests(common.BaseVolumeTests):
xfer_name = uuid.uuid4().hex
# create a volume
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 1 ' +
- volume_name
- ))
+ cmd_output = self.openstack(
+ 'volume create ' +
+ '--size 1 ' + volume_name,
+ parse_output=True,
+ )
self.assertEqual(volume_name, cmd_output['name'])
self.addCleanup(
self.openstack,
@@ -83,29 +83,31 @@ class TransferRequestTests(common.BaseVolumeTests):
)
self.wait_for_status("volume", volume_name, "available")
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request create -f json ' +
- ' --name ' + xfer_name + ' ' +
- volume_name
- ))
+ 'volume transfer request create ' +
+ ' --name ' + xfer_name + ' ' + volume_name,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
xfer_id = cmd_output['id']
auth_key = cmd_output['auth_key']
self.assertTrue(auth_key)
self.wait_for_status("volume", volume_name, "awaiting-transfer")
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request list -f json'
- ))
+ 'volume transfer request list',
+ parse_output=True,
+ )
self.assertIn(xfer_name, [req['Name'] for req in cmd_output])
- cmd_output = json.loads(self.openstack(
+ cmd_output = self.openstack(
'--os-volume-api-version ' + self.API_VERSION + ' ' +
- 'volume transfer request show -f json ' +
- xfer_id
- ))
+ 'volume transfer request show ' +
+ xfer_id,
+ parse_output=True,
+ )
self.assertEqual(xfer_name, cmd_output['name'])
# NOTE(dtroyer): We need to delete the transfer request to allow the
diff --git a/openstackclient/tests/functional/volume/v3/test_volume.py b/openstackclient/tests/functional/volume/v3/test_volume.py
index c1b45e2f..8a394e75 100644
--- a/openstackclient/tests/functional/volume/v3/test_volume.py
+++ b/openstackclient/tests/functional/volume/v3/test_volume.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v3 import common
@@ -22,22 +21,20 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 1 ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'volume create --size 1 ' + name1,
+ parse_output=True,
+ )
self.assertEqual(
1,
cmd_output["size"],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 2 ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'volume create --size 2 ' + name2,
+ parse_output=True,
+ )
self.assertEqual(
2,
cmd_output["size"],
@@ -51,11 +48,10 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_list(self):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 1 ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'volume create --size 1 ' + name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name1)
self.assertEqual(
1,
@@ -64,11 +60,10 @@ class VolumeTests(common.BaseVolumeTests):
self.wait_for_status("volume", name1, "available")
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 2 ' +
- name2
- ))
+ cmd_output = self.openstack(
+ 'volume create --size 2 ' + name2,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name2)
self.assertEqual(
2,
@@ -83,19 +78,19 @@ class VolumeTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test list --long
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '--long'
- ))
+ cmd_output = self.openstack(
+ 'volume list --long',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
# Test list --status
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '--status error'
- ))
+ cmd_output = self.openstack(
+ 'volume list --status error',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
@@ -107,13 +102,14 @@ class VolumeTests(common.BaseVolumeTests):
"""Tests create volume, set, unset, show, delete"""
name = uuid.uuid4().hex
new_name = name + "_"
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--size 1 ' +
'--description aaaa ' +
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + new_name)
self.assertEqual(
name,
@@ -154,10 +150,10 @@ class VolumeTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
self.wait_for_status("volume", new_name, "available")
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' + new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -192,10 +188,10 @@ class VolumeTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume show ' + new_name,
+ parse_output=True,
+ )
self.assertEqual(
{'Gamma': 'c'},
cmd_output["properties"],
@@ -211,30 +207,31 @@ class VolumeTests(common.BaseVolumeTests):
volume_name = uuid.uuid4().hex
snapshot_name = uuid.uuid4().hex
# Make a snapshot
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 1 ' +
- volume_name
- ))
+ cmd_output = self.openstack(
+ 'volume create --size 1 ' + volume_name,
+ parse_output=True,
+ )
self.wait_for_status("volume", volume_name, "available")
self.assertEqual(
volume_name,
cmd_output["name"],
)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
snapshot_name +
- ' --volume ' + volume_name
- ))
+ ' --volume ' + volume_name,
+ parse_output=True,
+ )
self.wait_for_status("volume snapshot", snapshot_name, "available")
name = uuid.uuid4().hex
# Create volume from snapshot
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
+ cmd_output = self.openstack(
+ 'volume create ' +
'--snapshot ' + snapshot_name +
- ' ' + name
- ))
+ ' ' + name,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name)
self.addCleanup(self.openstack, 'volume delete ' + volume_name)
self.assertEqual(
@@ -254,11 +251,10 @@ class VolumeTests(common.BaseVolumeTests):
def test_volume_list_backward_compatibility(self):
"""Test backward compatibility of list command"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume create -f json ' +
- '--size 1 ' +
- name1
- ))
+ cmd_output = self.openstack(
+ 'volume create --size 1 ' + name1,
+ parse_output=True,
+ )
self.addCleanup(self.openstack, 'volume delete ' + name1)
self.assertEqual(
1,
@@ -267,17 +263,17 @@ class VolumeTests(common.BaseVolumeTests):
self.wait_for_status("volume", name1, "available")
# Test list -c "Display Name"
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '-c "Display Name"'
- ))
+ cmd_output = self.openstack(
+ 'volume list -c "Display Name"',
+ parse_output=True,
+ )
for each_volume in cmd_output:
self.assertIn('Display Name', each_volume)
# Test list -c "Name"
- cmd_output = json.loads(self.openstack(
- 'volume list -f json ' +
- '-c "Name"'
- ))
+ cmd_output = self.openstack(
+ 'volume list -c "Name"',
+ parse_output=True,
+ )
for each_volume in cmd_output:
self.assertIn('Name', each_volume)
diff --git a/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py b/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py
index edfdafb6..7b2d88d0 100644
--- a/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py
+++ b/openstackclient/tests/functional/volume/v3/test_volume_snapshot.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import uuid
from openstackclient.tests.functional.volume.v3 import common
@@ -25,11 +24,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def setUpClass(cls):
super(VolumeSnapshotTests, cls).setUpClass()
# create a volume for all tests to create snapshot
- cmd_output = json.loads(cls.openstack(
- 'volume create -f json ' +
+ cmd_output = cls.openstack(
+ 'volume create ' +
'--size 1 ' +
- cls.VOLLY
- ))
+ cls.VOLLY,
+ parse_output=True,
+ )
cls.wait_for_status('volume', cls.VOLLY, 'available')
cls.VOLUME_ID = cmd_output['id']
@@ -46,22 +46,24 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def test_volume_snapshot_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name1 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.assertEqual(
name1,
cmd_output["name"],
)
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name2 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.assertEqual(
name2,
cmd_output["name"],
@@ -79,11 +81,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
def test_volume_snapshot_list(self):
"""Test create, list filter"""
name1 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name1 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', name1)
self.addCleanup(self.openstack, 'volume snapshot delete ' + name1)
self.assertEqual(
@@ -101,11 +104,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.wait_for_status('volume snapshot', name1, 'available')
name2 = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
name2 +
- ' --volume ' + self.VOLLY
- ))
+ ' --volume ' + self.VOLLY,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', name2)
self.addCleanup(self.openstack, 'volume snapshot delete ' + name2)
self.assertEqual(
@@ -129,29 +133,32 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Test list --long, --status
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
'--long ' +
- '--status error'
- ))
+ '--status error',
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertNotIn(name1, names)
self.assertIn(name2, names)
# Test list --volume
- cmd_output = json.loads(self.openstack(
- 'volume snapshot list -f json ' +
- '--volume ' + self.VOLLY
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
+ '--volume ' + self.VOLLY,
+ parse_output=True,
+ )
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(
- 'volume snapshot list -f json ' +
- '--name ' + name1
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot list ' +
+ '--name ' + name1,
+ parse_output=True,
+ )
names = [x["Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
@@ -160,13 +167,14 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
"""Test create, set, unset, show, delete volume snapshot"""
name = uuid.uuid4().hex
new_name = name + "_"
- cmd_output = json.loads(self.openstack(
- 'volume snapshot create -f json ' +
+ cmd_output = self.openstack(
+ 'volume snapshot create ' +
'--volume ' + self.VOLLY +
' --description aaaa ' +
'--property Alpha=a ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.addCleanup(self.wait_for_delete, 'volume snapshot', new_name)
self.addCleanup(self.openstack, 'volume snapshot delete ' + new_name)
self.assertEqual(
@@ -199,10 +207,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
self.assertOutput('', raw_output)
# Show snapshot set result
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
new_name,
cmd_output["name"],
@@ -228,10 +237,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertEqual(
{'Beta': 'b'},
cmd_output["properties"],
@@ -244,10 +254,11 @@ class VolumeSnapshotTests(common.BaseVolumeTests):
new_name,
)
self.assertOutput('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume snapshot show -f json ' +
- new_name
- ))
+ cmd_output = self.openstack(
+ 'volume snapshot show ' +
+ new_name,
+ parse_output=True,
+ )
self.assertNotIn(
{'Beta': 'b'},
cmd_output["properties"],
diff --git a/openstackclient/tests/functional/volume/v3/test_volume_type.py b/openstackclient/tests/functional/volume/v3/test_volume_type.py
index 165c625c..18e46c52 100644
--- a/openstackclient/tests/functional/volume/v3/test_volume_type.py
+++ b/openstackclient/tests/functional/volume/v3/test_volume_type.py
@@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
import time
import uuid
@@ -22,36 +21,40 @@ class VolumeTypeTests(common.BaseVolumeTests):
def test_volume_type_create_list(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name,
)
self.assertEqual(name, cmd_output['name'])
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual(name, cmd_output['name'])
- cmd_output = json.loads(self.openstack('volume type list -f json'))
+ cmd_output = self.openstack('volume type list', parse_output=True)
self.assertIn(name, [t['Name'] for t in cmd_output])
- cmd_output = json.loads(self.openstack(
- 'volume type list -f json --default'
- ))
+ cmd_output = self.openstack(
+ 'volume type list --default',
+ parse_output=True,
+ )
self.assertEqual(1, len(cmd_output))
self.assertEqual('lvmdriver-1', cmd_output[0]['Name'])
def test_volume_type_set_unset_properties(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -62,26 +65,29 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type set --property a=b --property c=d %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
raw_output = self.openstack(
'volume type unset --property a %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'c': 'd'}, cmd_output['properties'])
def test_volume_type_set_unset_multiple_properties(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -92,26 +98,29 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type set --property a=b --property c=d %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({'a': 'b', 'c': 'd'}, cmd_output['properties'])
raw_output = self.openstack(
'volume type unset --property a --property c %s' % name
)
self.assertEqual("", raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json %s' % name
- ))
+ cmd_output = self.openstack(
+ 'volume type show %s' % name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output['properties'])
def test_volume_type_set_unset_project(self):
name = uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name
@@ -147,13 +156,15 @@ class VolumeTypeTests(common.BaseVolumeTests):
name = uuid.uuid4().hex
encryption_type = uuid.uuid4().hex
# test create new encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json '
+ cmd_output = self.openstack(
+ 'volume type create '
'--encryption-provider LuksEncryptor '
'--encryption-cipher aes-xts-plain64 '
'--encryption-key-size 128 '
'--encryption-control-location front-end ' +
- encryption_type))
+ encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -161,8 +172,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test show encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + encryption_type))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -170,8 +183,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test list encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type list -f json --encryption-type'))
+ cmd_output = self.openstack(
+ 'volume type list --encryption-type',
+ parse_output=True,
+ )
encryption_output = [t['Encryption'] for t in cmd_output
if t['Name'] == encryption_type][0]
expected = {'provider': 'LuksEncryptor',
@@ -187,8 +202,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
'--encryption-control-location back-end ' +
encryption_type)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + encryption_type))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + encryption_type,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 256,
@@ -196,10 +213,11 @@ class VolumeTypeTests(common.BaseVolumeTests):
for attr, value in expected.items():
self.assertEqual(value, cmd_output['encryption'][attr])
# test set new encryption type
- cmd_output = json.loads(self.openstack(
- 'volume type create -f json --private ' +
+ cmd_output = self.openstack(
+ 'volume type create --private ' +
name,
- ))
+ parse_output=True,
+ )
self.addCleanup(
self.openstack,
'volume type delete ' + name,
@@ -215,9 +233,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
name)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + name
- ))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + name,
+ parse_output=True,
+ )
expected = {'provider': 'LuksEncryptor',
'cipher': 'aes-xts-plain64',
'key_size': 128,
@@ -229,9 +248,10 @@ class VolumeTypeTests(common.BaseVolumeTests):
'volume type unset --encryption-type ' + name
)
self.assertEqual('', raw_output)
- cmd_output = json.loads(self.openstack(
- 'volume type show -f json --encryption-type ' + name
- ))
+ cmd_output = self.openstack(
+ 'volume type show --encryption-type ' + name,
+ parse_output=True,
+ )
self.assertEqual({}, cmd_output['encryption'])
# test delete encryption type
raw_output = self.openstack('volume type delete ' + encryption_type)