Debian Codegraph @

ironic_tempest_plugin/tests/scenario/ironic_standalone/test_advanced_ops.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from oslo_log import log as logging
14 from tempest.common import utils
15 from tempest import config
16 from tempest.lib.common.utils import data_utils
17 from tempest.lib import decorators
18
19
20 from ironic_tempest_plugin.tests.scenario import \
21 baremetal_standalone_manager as bsm
22
23 CONF = config.CONF
24
25
26 LOG = logging.getLogger(__name__)
27
28
29 class BaremetalRedfishDHCPLessDeploy(bsm.BaremetalStandaloneScenarioTest):
30
31 api_microversion = '1.59' # Ussuri for redfish-virtual-media
32 driver = 'redfish'
33 deploy_interface = 'direct'
34 boot_interface = 'redfish-virtual-media'
35 # To force interface retoggling.
36 image_ref = CONF.baremetal.whole_disk_image_ref
37 image_checksum = CONF.baremetal.whole_disk_image_checksum
38 wholedisk_image = True
39
40 @classmethod
41 def skip_checks(cls):
42 super(BaremetalRedfishDHCPLessDeploy, cls).skip_checks()
43 if CONF.baremetal_feature_enabled.dhcpless_vmedia:
44 raise cls.skipException("This test requires a full OS image to "
45 "be deployed, and thus must be "
46 "explicitly enabled for testing.")
47
48 if (not CONF.baremetal.public_subnet_id
49 or not CONF.baremetal.public_subnet_ip):
50 raise cls.skipException(
51 "This test requires a public sunbet ID, and public subnet "
52 "IP to use on that subnet to execute. Please see the "
53 "baremetal configuration options public_subnet_id "
54 "and public_subnet_ip respectively, and populate with "
55 "appropriate values to execute this test.")
56
57 def create_tenant_network(self, clients, tenant_cidr, ip_version):
58 # NOTE(TheJulia): self.create_network is an internal method
59 # which just gets the info, doesn't actually create a network.
60 network = self.create_network(
61 networks_client=self.os_admin.networks_client,
62 project_id=clients.credentials.project_id,
63 shared=True)
64
65 router = self.get_router(
66 client=clients.routers_client,
67 project_id=clients.credentials.tenant_id,
68 external_gateway_info={
69 'network_id': CONF.network.public_network_id,
70 'external_fixed_ips': [
71 {'subnet_id': CONF.baremetal.public_subnet_id,
72 'ip_address': CONF.baremetal.public_subnet_ip}]
73 })
74 result = clients.subnets_client.create_subnet(
75 name=data_utils.rand_name('subnet'),
76 network_id=network['id'],
77 tenant_id=clients.credentials.tenant_id,
78 ip_version=CONF.validation.ip_version_for_ssh,
79 cidr=tenant_cidr, enable_dhcp=False)
80 subnet = result['subnet']
81 clients.routers_client.add_router_interface(router['id'],
82 subnet_id=subnet['id'])
83 self.addCleanup(clients.subnets_client.delete_subnet, subnet['id'])
84 self.addCleanup(clients.routers_client.remove_router_interface,
85 router['id'], subnet_id=subnet['id'])
86 return network, subnet, router
87
88 def deploy_vmedia_dhcpless(self, rebuild=False):
89 """Helper to facilitate vmedia testing.
90
91 * Create Network/router without DHCP
92 * Set provisioning_network for this node.
93 * Set cleanup to undo the provisionign network setup.
94 * Launch instance.
95 * Requirement: Instance OS image supports network config from
96 network_data embedded in the OS. i.e. a real image, not
97 cirros.
98 * If so enabled, rebuild the node, Verify rebuild completed.
99 * Via cleanup: Teardown Network/Router
100 """
101
102 # Get the latest state for the node.
103 self.node = self.get_node(self.node['uuid'])
104 # This test, as far as I'm remembering after the fact, was developed
105 # in an environment where neutron was the default network interface.
106 # so we must try to set it to properly ensure dhcp-less operation.
107 prior_prov_net = self.node['driver_info'].get('provisioning_network')
108 if self.node['network_interface'] != 'neutron':
109 try:
110 self.client.update_node(self.node['uuid'],
111 [{'path': '/network_interface',
112 'op': 'replace',
113 'value': 'neutron'}])
114 self.addCleanup(self.update_node,
115 self.node['uuid'],
116 [{'op': 'replace',
117 'path': '/network_interface',
118 'value': 'flat'}])
119 except Exception as e:
120 LOG.debug('Encountered error attempting to set the '
121 'network_interface to neutron. Error: %s', e)
122 raise self.skipException(
123 "Ironic configuration incorrect to exercise this test.")
124
125 ip_version = CONF.validation.ip_version_for_ssh
126 tenant_cidr = '10.0.6.0/24'
127 if ip_version == 6:
128 tenant_cidr = 'fd00:33::/64'
129
130 network, subnet, router = self.create_tenant_network(
131 self.os_admin, tenant_cidr, ip_version=ip_version)
132 if prior_prov_net:
133 self.update_node(self.node['uuid'],
134 [{'op': 'replace',
135 'path': '/driver_info/provisioning_network',
136 'value': network['id']}])
137 self.addCleanup(self.update_node,
138 self.node['uuid'],
139 [{'op': 'replace',
140 'path': '/driver_info/provisioning_network',
141 'value': prior_prov_net}])
142 else:
143 self.update_node(self.node['uuid'],
144 [{'op': 'add',
145 'path': '/driver_info/provisioning_network',
146 'value': network['id']}])
147 self.addCleanup(self.update_node,
148 self.node['uuid'],
149 [{'op': 'remove',
150 'path': '/driver_info/provisioning_network'}])
151
152 self.set_node_to_active(self.image_ref, self.image_checksum,
153 fallback_network=network['id'],
154 config_drive_networking=True,
155 method_to_get_ip=self.get_server_ip)
156
157 # node_ip is set by the prior call to set_node_to_active
158 self.assertTrue(self.ping_ip_address(self.node_ip))
159
160 if rebuild:
161 self.set_node_provision_state(self.node['uuid'], 'rebuild')
162 self.wait_provisioning_state(self.node['uuid'], 'active',
163 timeout=CONF.baremetal.active_timeout,
164 interval=30)
165 # NOTE(TheJulia): We explicitly don't ping in this test as
166 # what we are testing is that we are able to return to active.
167 # i.e. That the agent is operating as designed.
168 # Force delete so we remove the vifs
169 self.terminate_node(self.node['uuid'], force_delete=True)
170
171 @decorators.idempotent_id('1f420ef3-99bd-46c7-b859-ce9c2892697f')
172 @utils.services('image', 'network')
173 def test_ip_access_to_server(self):
174 self.deploy_vmedia_dhcpless(
175 rebuild=CONF.baremetal.rebuild_remote_dhcpless)