Fix nova scenarios for assiciating fips
Two scenarios were not properly adopted while switching from network wrapper usage Change-Id: I677d45d11614acf48b979db1c64fc115cedd612e
This commit is contained in:
parent
09c040fa70
commit
ab03bfeafd
@ -901,31 +901,46 @@ class BootAndRebuildServer(utils.NovaScenario):
|
|||||||
self._delete_server(server)
|
self._delete_server(server)
|
||||||
|
|
||||||
|
|
||||||
|
@logging.log_deprecated_args(
|
||||||
|
"Use 'floating_network' for additional instance parameters.",
|
||||||
|
"2.1.0", ["create_floating_ip_args"], once=True)
|
||||||
@types.convert(image={"type": "glance_image"},
|
@types.convert(image={"type": "glance_image"},
|
||||||
flavor={"type": "nova_flavor"})
|
flavor={"type": "nova_flavor"})
|
||||||
@validation.add("image_valid_on_flavor", flavor_param="flavor",
|
@validation.add("image_valid_on_flavor", flavor_param="flavor",
|
||||||
image_param="image")
|
image_param="image")
|
||||||
@validation.add("required_services", services=[consts.Service.NOVA])
|
@validation.add("required_services", services=[consts.Service.NOVA])
|
||||||
@validation.add("required_platform", platform="openstack", users=True)
|
@validation.add("required_platform", platform="openstack", users=True)
|
||||||
@validation.add("required_contexts", contexts=("network"))
|
@validation.add("required_contexts", contexts=["network"])
|
||||||
@scenario.configure(
|
@scenario.configure(
|
||||||
context={"cleanup@openstack": ["nova", "neutron.floatingip"]},
|
context={"cleanup@openstack": ["nova", "neutron.floatingip"]},
|
||||||
name="NovaServers.boot_and_associate_floating_ip",
|
name="NovaServers.boot_and_associate_floating_ip",
|
||||||
platform="openstack")
|
platform="openstack")
|
||||||
class BootAndAssociateFloatingIp(utils.NovaScenario):
|
class BootAndAssociateFloatingIp(utils.NovaScenario):
|
||||||
|
|
||||||
def run(self, image, flavor, create_floating_ip_args=None, **kwargs):
|
def run(self, image, flavor, floating_network=None,
|
||||||
|
create_floating_ip_args=None, **kwargs):
|
||||||
"""Boot a server and associate a floating IP to it.
|
"""Boot a server and associate a floating IP to it.
|
||||||
|
|
||||||
:param image: image to be used to boot an instance
|
:param image: image to be used to boot an instance
|
||||||
:param flavor: flavor to be used to boot an instance
|
:param flavor: flavor to be used to boot an instance
|
||||||
:param create_floating_ip_args: Optional additional arguments for
|
:param floating_network: external network associated with floating IP.
|
||||||
floating ip creation
|
:param create_floating_ip_args: Optional additional dict for specifying
|
||||||
|
external network associated with floating IP ('ext_network' key).
|
||||||
:param kwargs: Optional additional arguments for server creation
|
:param kwargs: Optional additional arguments for server creation
|
||||||
"""
|
"""
|
||||||
create_floating_ip_args = create_floating_ip_args or {}
|
if floating_network is None and create_floating_ip_args:
|
||||||
|
if "ext_network" in create_floating_ip_args:
|
||||||
|
# the old way (network wrapper)
|
||||||
|
floating_network = create_floating_ip_args["ext_network"]
|
||||||
|
elif "floating_network" in create_floating_ip_args:
|
||||||
|
# the semi-old way - the time when network wrapper was replaced
|
||||||
|
# by network service, but this compatibility layer was not
|
||||||
|
# provided
|
||||||
|
floating_network = create_floating_ip_args["floating_network"]
|
||||||
server = self._boot_server(image, flavor, **kwargs)
|
server = self._boot_server(image, flavor, **kwargs)
|
||||||
floatingip = self.neutron.create_floatingip(**create_floating_ip_args)
|
floatingip = self.neutron.create_floatingip(
|
||||||
|
floating_network=floating_network
|
||||||
|
)
|
||||||
self._associate_floating_ip(server, floatingip)
|
self._associate_floating_ip(server, floatingip)
|
||||||
|
|
||||||
|
|
||||||
@ -1083,20 +1098,24 @@ class BootServerFromVolumeSnapshot(utils.NovaScenario,
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@logging.log_deprecated_args(
|
||||||
|
"Use 'floating_network' for additional instance parameters.",
|
||||||
|
"2.1.0", ["create_floating_ip_args"], once=True)
|
||||||
@types.convert(image={"type": "glance_image"},
|
@types.convert(image={"type": "glance_image"},
|
||||||
flavor={"type": "nova_flavor"})
|
flavor={"type": "nova_flavor"})
|
||||||
@validation.add("image_valid_on_flavor", flavor_param="flavor",
|
@validation.add("image_valid_on_flavor", flavor_param="flavor",
|
||||||
image_param="image")
|
image_param="image")
|
||||||
@validation.add("required_services", services=[consts.Service.NOVA])
|
@validation.add("required_services", services=[consts.Service.NOVA])
|
||||||
@validation.add("required_platform", platform="openstack", users=True)
|
@validation.add("required_platform", platform="openstack", users=True)
|
||||||
@validation.add("required_contexts", contexts=("network"))
|
@validation.add("required_contexts", contexts=["network"])
|
||||||
@scenario.configure(
|
@scenario.configure(
|
||||||
context={"cleanup@openstack": ["nova", "neutron.floatingip"]},
|
context={"cleanup@openstack": ["nova", "neutron.floatingip"]},
|
||||||
name="NovaServers.boot_server_associate_and_dissociate_floating_ip",
|
name="NovaServers.boot_server_associate_and_dissociate_floating_ip",
|
||||||
platform="openstack")
|
platform="openstack")
|
||||||
class BootServerAssociateAndDissociateFloatingIP(utils.NovaScenario):
|
class BootServerAssociateAndDissociateFloatingIP(utils.NovaScenario):
|
||||||
|
|
||||||
def run(self, image, flavor, create_floating_ip_args=None, **kwargs):
|
def run(self, image, flavor, floating_network=None,
|
||||||
|
create_floating_ip_args=None, **kwargs):
|
||||||
"""Boot a server associate and dissociate a floating IP from it.
|
"""Boot a server associate and dissociate a floating IP from it.
|
||||||
|
|
||||||
The scenario first boot a server and create a floating IP. then
|
The scenario first boot a server and create a floating IP. then
|
||||||
@ -1105,14 +1124,24 @@ class BootServerAssociateAndDissociateFloatingIP(utils.NovaScenario):
|
|||||||
|
|
||||||
:param image: image to be used to boot an instance
|
:param image: image to be used to boot an instance
|
||||||
:param flavor: flavor to be used to boot an instance
|
:param flavor: flavor to be used to boot an instance
|
||||||
:param create_floating_ip_args: Optional additional arguments for
|
:param floating_network: external network associated with floating IP.
|
||||||
floating ip creation
|
:param create_floating_ip_args: Optional additional dict for specifying
|
||||||
|
external network associated with floating IP ('ext_network' key).
|
||||||
:param kwargs: Optional additional arguments for server creation
|
:param kwargs: Optional additional arguments for server creation
|
||||||
"""
|
"""
|
||||||
|
if floating_network is None and create_floating_ip_args:
|
||||||
create_floating_ip_args = create_floating_ip_args or {}
|
if "ext_network" in create_floating_ip_args:
|
||||||
|
# the old way (network wrapper)
|
||||||
|
floating_network = create_floating_ip_args["ext_network"]
|
||||||
|
elif "floating_network" in create_floating_ip_args:
|
||||||
|
# the semi-old way - the time when network wrapper was replaced
|
||||||
|
# by network service, but this compatibility layer was not
|
||||||
|
# provided
|
||||||
|
floating_network = create_floating_ip_args["floating_network"]
|
||||||
server = self._boot_server(image, flavor, **kwargs)
|
server = self._boot_server(image, flavor, **kwargs)
|
||||||
floatingip = self.neutron.create_floatingip(**create_floating_ip_args)
|
floatingip = self.neutron.create_floatingip(
|
||||||
|
floating_network=floating_network
|
||||||
|
)
|
||||||
self._associate_floating_ip(server, floatingip)
|
self._associate_floating_ip(server, floatingip)
|
||||||
self._dissociate_floating_ip(server, floatingip)
|
self._dissociate_floating_ip(server, floatingip)
|
||||||
|
|
||||||
@ -1123,7 +1152,7 @@ class BootServerAssociateAndDissociateFloatingIP(utils.NovaScenario):
|
|||||||
image_param="image")
|
image_param="image")
|
||||||
@validation.add("required_services", services=[consts.Service.NOVA])
|
@validation.add("required_services", services=[consts.Service.NOVA])
|
||||||
@validation.add("required_platform", platform="openstack", users=True)
|
@validation.add("required_platform", platform="openstack", users=True)
|
||||||
@validation.add("required_contexts", contexts=("network"))
|
@validation.add("required_contexts", contexts=["network"])
|
||||||
@scenario.configure(context={"cleanup@openstack": ["nova"]},
|
@scenario.configure(context={"cleanup@openstack": ["nova"]},
|
||||||
name="NovaServers.boot_server_and_list_interfaces",
|
name="NovaServers.boot_server_and_list_interfaces",
|
||||||
platform="openstack")
|
platform="openstack")
|
||||||
|
@ -41,9 +41,7 @@
|
|||||||
"image": {
|
"image": {
|
||||||
"name": "^cirros.*-disk$"
|
"name": "^cirros.*-disk$"
|
||||||
},
|
},
|
||||||
"create_floating_ip_args": {
|
"floating_network": "ext_network_name"
|
||||||
"ext_network": "ext_network_name"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"context": {
|
"context": {
|
||||||
"users": {
|
"users": {
|
||||||
|
@ -25,8 +25,7 @@
|
|||||||
name: "{{flavor_name}}"
|
name: "{{flavor_name}}"
|
||||||
image:
|
image:
|
||||||
name: "^cirros.*-disk$"
|
name: "^cirros.*-disk$"
|
||||||
create_floating_ip_args:
|
floating_network: "ext_network_name"
|
||||||
ext_network: "ext_network_name"
|
|
||||||
runner:
|
runner:
|
||||||
type: "constant"
|
type: "constant"
|
||||||
times: 1
|
times: 1
|
||||||
|
@ -41,9 +41,7 @@
|
|||||||
"image": {
|
"image": {
|
||||||
"name": "^cirros.*-disk$"
|
"name": "^cirros.*-disk$"
|
||||||
},
|
},
|
||||||
"create_floating_ip_args": {
|
"floating_network": "ext_network_name"
|
||||||
"ext_network": "ext_network_name"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"context": {
|
"context": {
|
||||||
"users": {
|
"users": {
|
||||||
|
@ -25,8 +25,7 @@
|
|||||||
name: "{{flavor_name}}"
|
name: "{{flavor_name}}"
|
||||||
image:
|
image:
|
||||||
name: "^cirros.*-disk$"
|
name: "^cirros.*-disk$"
|
||||||
create_floating_ip_args:
|
floating_network: "ext_network_name"
|
||||||
ext_network: "ext_network_name"
|
|
||||||
runner:
|
runner:
|
||||||
type: "constant"
|
type: "constant"
|
||||||
times: 5
|
times: 5
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
ALLOWED_EXTRA_MISSING=10
|
ALLOWED_EXTRA_MISSING=4
|
||||||
|
|
||||||
show_diff () {
|
show_diff () {
|
||||||
head -1 $1
|
head -1 $1
|
||||||
|
@ -944,6 +944,55 @@ class NovaServersTestCase(test.ScenarioTestCase):
|
|||||||
scenario._associate_floating_ip.assert_called_once_with(
|
scenario._associate_floating_ip.assert_called_once_with(
|
||||||
server, floatingip)
|
server, floatingip)
|
||||||
|
|
||||||
|
# check ext_network
|
||||||
|
neutronclient.list_networks.return_value = {
|
||||||
|
"networks": [
|
||||||
|
{"id": "id1", "name": "net1", "router:external": True},
|
||||||
|
{"id": "id2", "name": "net2", "router:external": True},
|
||||||
|
{"id": "id3", "name": "net3", "router:external": True},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
|
||||||
|
# case 1: new argument is used
|
||||||
|
scenario.run(image, flavor, floating_network="net3")
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id3"}}
|
||||||
|
)
|
||||||
|
# case 2: new argument is transmitted with an old one
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor, floating_network="net3",
|
||||||
|
create_floating_ip_args={"ext_network": "net2"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id3"}}
|
||||||
|
)
|
||||||
|
# case 3: new argument is transmitted with an semi-old one
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor, floating_network="net3",
|
||||||
|
create_floating_ip_args={"floating_network": "net1"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id3"}}
|
||||||
|
)
|
||||||
|
# case 4: only old argument is transmitted
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor,
|
||||||
|
create_floating_ip_args={"ext_network": "net2"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id2"}}
|
||||||
|
)
|
||||||
|
# case 5: only semi-old argument is transmitted
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor,
|
||||||
|
create_floating_ip_args={"floating_network": "net1"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id1"}}
|
||||||
|
)
|
||||||
|
|
||||||
def test_boot_server_associate_and_dissociate_floating_ip(self):
|
def test_boot_server_associate_and_dissociate_floating_ip(self):
|
||||||
clients = mock.MagicMock()
|
clients = mock.MagicMock()
|
||||||
neutronclient = clients.neutron.return_value
|
neutronclient = clients.neutron.return_value
|
||||||
@ -972,6 +1021,55 @@ class NovaServersTestCase(test.ScenarioTestCase):
|
|||||||
scenario._dissociate_floating_ip.assert_called_once_with(
|
scenario._dissociate_floating_ip.assert_called_once_with(
|
||||||
server, floatingip)
|
server, floatingip)
|
||||||
|
|
||||||
|
# check ext_network
|
||||||
|
neutronclient.list_networks.return_value = {
|
||||||
|
"networks": [
|
||||||
|
{"id": "id1", "name": "net1", "router:external": True},
|
||||||
|
{"id": "id2", "name": "net2", "router:external": True},
|
||||||
|
{"id": "id3", "name": "net3", "router:external": True},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
|
||||||
|
# case 1: new argument is used
|
||||||
|
scenario.run(image, flavor, floating_network="net3")
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id3"}}
|
||||||
|
)
|
||||||
|
# case 2: new argument is transmitted with an old one
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor, floating_network="net3",
|
||||||
|
create_floating_ip_args={"ext_network": "net2"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id3"}}
|
||||||
|
)
|
||||||
|
# case 3: new argument is transmitted with an semi-old one
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor, floating_network="net3",
|
||||||
|
create_floating_ip_args={"floating_network": "net1"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id3"}}
|
||||||
|
)
|
||||||
|
# case 4: only old argument is transmitted
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor,
|
||||||
|
create_floating_ip_args={"ext_network": "net2"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id2"}}
|
||||||
|
)
|
||||||
|
# case 5: only semi-old argument is transmitted
|
||||||
|
neutronclient.create_floatingip.reset_mock()
|
||||||
|
scenario.run(image, flavor,
|
||||||
|
create_floating_ip_args={"floating_network": "net1"})
|
||||||
|
neutronclient.create_floatingip.assert_called_once_with(
|
||||||
|
{"floatingip": {"description": mock.ANY,
|
||||||
|
"floating_network_id": "id1"}}
|
||||||
|
)
|
||||||
|
|
||||||
def test_boot_and_update_server(self):
|
def test_boot_and_update_server(self):
|
||||||
scenario = servers.BootAndUpdateServer(self.context)
|
scenario = servers.BootAndUpdateServer(self.context)
|
||||||
scenario._boot_server = mock.Mock()
|
scenario._boot_server = mock.Mock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user