OpenStack Compute (Nova)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.1KB

  1. # Copyright 2017 NTT Corporation.
  2. #
  3. # All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. from oslo_utils.fixture import uuidsentinel as uuids
  17. from nova.tests import fixtures as nova_fixtures
  18. from nova.tests.functional.api import client
  19. from nova.tests.functional import integrated_helpers
  20. from nova.tests.functional import test_servers
  21. from nova.tests.unit import policy_fixture
  22. def create_request_body():
  23. return {
  24. "interfaceAttachment": {
  25. "port_id": uuids.port,
  26. "net_id": uuids.net,
  27. "fixed_ips": [
  28. {
  29. "ip_address": "192.168.1.3",
  30. "subnet_id": uuids.subnet
  31. }
  32. ]
  33. }
  34. }
  35. class InterfaceFullstack(integrated_helpers._IntegratedTestBase):
  36. """Tests for port interfaces command.
  37. Extension: os-interface
  38. os-interface adds a set of functions to the port interfaces
  39. for the creation and deletion of port interfaces.
  40. POST /v2.1/{tenant_id}/servers/{server_id}/os-interface
  41. DELETE /v2.1/{tenant_id}/servers/{server_id}/os-interface/{attachment_id}
  42. Functional Test Scope:
  43. This test starts the wsgi stack for the nova api services, uses an
  44. in memory database to ensure the path through the wsgi layer to
  45. the database.
  46. """
  47. api_major_version = 'v2.1'
  48. USE_NEUTRON = False
  49. _image_ref_parameter = 'imageRef'
  50. _flavor_ref_parameter = 'flavorRef'
  51. def setUp(self):
  52. super(InterfaceFullstack, self).setUp()
  53. self.useFixture(policy_fixture.RealPolicyFixture())
  54. api_fixture = self.useFixture(nova_fixtures.OSAPIFixture())
  55. self.api = api_fixture.api
  56. def test_interface_func_negative(self):
  57. """Test port interface edge conditions.
  58. - Bogus body is a 400
  59. """
  60. # Create a server
  61. server = self._build_minimal_create_server_request()
  62. created_server = self.api.post_server({"server": server})
  63. created_server_id = created_server['id']
  64. # Test for API failure conditions
  65. # bad body is 400
  66. os_interface_url = '/servers/%s/os-interface' % created_server_id
  67. # Check in the case that both net_id and port_id are specified.
  68. body = create_request_body()
  69. del body['interfaceAttachment']['fixed_ips']
  70. resp = self.api.api_post(os_interface_url, body,
  71. check_response_status=False)
  72. self.assertEqual(400, resp.status)
  73. # Check in the case that fixed_ips is specified,
  74. # but net_id is not specifed.
  75. body = create_request_body()
  76. del body['interfaceAttachment']['port_id']
  77. del body['interfaceAttachment']['net_id']
  78. resp = self.api.api_post(os_interface_url, body,
  79. check_response_status=False)
  80. self.assertEqual(400, resp.status)
  81. class InterfaceFullstackWithNeutron(test_servers.ServersTestBase):
  82. """Tests for port interfaces command.
  83. Functional Test Scope:
  84. This test uses Neutron.
  85. os-interface API specifies a port ID created by Neutron.
  86. """
  87. api_major_version = 'v2.1'
  88. def test_detach_interface_negative_invalid_state(self):
  89. # Create server with network
  90. image = self.api.get_images()[0]['id']
  91. post = {"server": {"name": "test", "flavorRef": "1",
  92. "imageRef": image,
  93. "networks": [{"uuid": "3cb9bc59-5699-4588-a4b1-b87f96708bc6"}]}}
  94. created_server = self.api.post_server(post)
  95. created_server_id = created_server['id']
  96. found_server = self._wait_for_state_change(created_server, 'ACTIVE')
  97. post = {
  98. 'interfaceAttachment': {
  99. 'net_id': "3cb9bc59-5699-4588-a4b1-b87f96708bc6"
  100. }
  101. }
  102. self.api.attach_interface(created_server_id, post)
  103. response = self.api.get_port_interfaces(created_server_id)[0]
  104. port_id = response['port_id']
  105. # Change status from ACTIVE to SUSPENDED for negative test
  106. post = {'suspend': {}}
  107. self.api.post_server_action(created_server_id, post)
  108. found_server = self._wait_for_state_change(found_server, 'SUSPENDED')
  109. # Detach port interface in SUSPENDED (not ACTIVE, etc.)
  110. ex = self.assertRaises(client.OpenStackApiException,
  111. self.api.detach_interface,
  112. created_server_id, port_id)
  113. self.assertEqual(409, ex.response.status_code)
  114. self.assertEqual('SUSPENDED', found_server['status'])
  115. # Cleanup
  116. self._delete_server(found_server)