summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional
diff options
context:
space:
mode:
authorDiwei Zhu <zhu.diw@northeastern.edu>2021-10-28 02:16:23 +0000
committerDiwei Zhu <zhu.diw@northeastern.edu>2021-11-14 15:23:36 +0000
commit2183a611475090347863917f6c90f0f38cd80893 (patch)
treea930e9c56e129168c18f67092852011ccf747192 /openstackclient/tests/functional
parentf824e13bc5754d3de108d39d62de3d6cfae2670c (diff)
downloadpython-openstackclient-2183a611475090347863917f6c90f0f38cd80893.tar.gz
Switch openstack server add port/network to using sdk.
The old novaclient.v2.server.Server.interface_attach() method is replaced with proxy.create_server_interface(). In swargs, 'net_id' and 'port_id' are mutual-exclusive, if one of them is given with value, the other one cannot be None, as the API would responde with 400 (None is not string). In unit test, temporary method 'setup_sdk_servers_mock' is added, because other tests are still using the old 'setup_servers_mock'. Functional tests are added. Releasenote is generated. Change-Id: I9899f0509febc5143560a1859ae6344d0a6d1427
Diffstat (limited to 'openstackclient/tests/functional')
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
index 9cf2fc7f..59b1fad5 100644
--- a/openstackclient/tests/functional/compute/v2/test_server.py
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -1071,3 +1071,51 @@ class ServerTests(common.ComputeTestCase):
# networks and the test didn't specify a specific network.
self.assertNotIn('nics are required after microversion 2.36',
e.stderr)
+
+ def test_server_add_remove_network_port(self):
+ name = uuid.uuid4().hex
+ cmd_output = json.loads(self.openstack(
+ 'server create -f json ' +
+ '--network private ' +
+ '--flavor ' + self.flavor_name + ' ' +
+ '--image ' + self.image_name + ' ' +
+ '--wait ' +
+ name
+ ))
+
+ self.assertIsNotNone(cmd_output['id'])
+ self.assertEqual(name, cmd_output['name'])
+
+ self.openstack(
+ 'server add network ' + name + ' public')
+
+ cmd_output = json.loads(self.openstack(
+ 'server show -f json ' + name
+ ))
+
+ addresses = cmd_output['addresses']
+ self.assertIn('public', addresses)
+
+ port_name = 'test-port'
+
+ cmd_output = json.loads(self.openstack(
+ 'port list -f json'
+ ))
+ self.assertNotIn(port_name, cmd_output)
+
+ cmd_output = json.loads(self.openstack(
+ 'port create -f json ' +
+ '--network private ' + port_name
+ ))
+ self.assertIsNotNone(cmd_output['id'])
+
+ self.openstack('server add port ' + name + ' ' + port_name)
+
+ cmd_output = json.loads(self.openstack(
+ 'server show -f json ' + name
+ ))
+
+ # TODO(diwei): test remove network/port after the commands are switched
+
+ self.openstack('server delete ' + name)
+ self.openstack('port delete ' + port_name)