How to use test_server_basic_ops method in tempest

Best Python code snippet using tempest_python

test_metadata.py

Source:test_metadata.py Github

copy

Full Screen

1# Copyright 2020 Ericsson Software Technology2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import collections15from neutron_lib import constants as nlib_const16from oslo_log import log as logging17from tempest.common import utils18from tempest.lib.common.utils import data_utils19from tempest.lib import decorators20from tempest.lib import exceptions21import testtools22from neutron_tempest_plugin.common import ssh23from neutron_tempest_plugin import config24from neutron_tempest_plugin.scenario import base25LOG = logging.getLogger(__name__)26CONF = config.CONF27Server = collections.namedtuple(28 'Server', ['floating_ip', 'server', 'ssh_client'])29class MetadataTest(base.BaseTempestTestCase):30 """Test metadata access over IPv6 tenant subnet.31 Please note that there is metadata over IPv4 test coverage in tempest:32 tempest.scenario.test_server_basic_ops\33 .TestServerBasicOps.test_server_basic_ops34 """35 credentials = ['primary', 'admin']36 force_tenant_isolation = False37 @classmethod38 def skip_checks(cls):39 super(MetadataTest, cls).skip_checks()40 if not utils.is_network_feature_enabled('ipv6_metadata'):41 raise cls.skipException("Metadata over IPv6 is not enabled")42 @classmethod43 def resource_setup(cls):44 super(MetadataTest, cls).resource_setup()45 cls.rand_name = data_utils.rand_name(46 cls.__name__.rsplit('.', 1)[-1])47 cls.reserve_external_subnet_cidrs()48 cls.network = cls.create_network(name=cls.rand_name)49 cls.subnet_v4 = cls.create_subnet(50 network=cls.network, name=cls.rand_name)51 cls.subnet_v6 = cls.create_subnet(52 network=cls.network, name=cls.rand_name, ip_version=6)53 cls.router = cls.create_router_by_client()54 cls.create_router_interface(cls.router['id'], cls.subnet_v4['id'])55 cls.create_router_interface(cls.router['id'], cls.subnet_v6['id'])56 cls.keypair = cls.create_keypair(name=cls.rand_name)57 cls.security_group = cls.create_security_group(name=cls.rand_name)58 cls.create_loginable_secgroup_rule(cls.security_group['id'])59 def _create_server_with_network(self, network, use_advanced_image=False):60 port = self._create_server_port(network=network)61 floating_ip = self.create_floatingip(port=port)62 ssh_client = self._create_ssh_client(63 floating_ip=floating_ip, use_advanced_image=use_advanced_image)64 server = self._create_server(port=port,65 use_advanced_image=use_advanced_image)66 return Server(67 floating_ip=floating_ip, server=server, ssh_client=ssh_client)68 def _create_server_port(self, network=None, **params):69 network = network or self.network70 return self.create_port(network=network, name=self.rand_name,71 security_groups=[self.security_group['id']],72 **params)73 def _create_server(self, port, use_advanced_image=False, **params):74 if use_advanced_image:75 flavor_ref = CONF.neutron_plugin_options.advanced_image_flavor_ref76 image_ref = CONF.neutron_plugin_options.advanced_image_ref77 else:78 flavor_ref = CONF.compute.flavor_ref79 image_ref = CONF.compute.image_ref80 return self.create_server(flavor_ref=flavor_ref,81 image_ref=image_ref,82 key_name=self.keypair['name'],83 networks=[{'port': port['id']}],84 **params)['server']85 def _create_ssh_client(self, floating_ip, use_advanced_image=False):86 if use_advanced_image:87 username = CONF.neutron_plugin_options.advanced_image_ssh_user88 else:89 username = CONF.validation.image_ssh_user90 return ssh.Client(host=floating_ip['floating_ip_address'],91 username=username,92 pkey=self.keypair['private_key'])93 def _assert_has_ssh_connectivity(self, ssh_client):94 ssh_client.exec_command('true')95 def _get_primary_interface(self, ssh_client):96 out = ssh_client.exec_command(97 "ip -6 -br address show scope link up | head -1 | cut -d ' ' -f1")98 interface = out.strip()99 if not interface:100 self.fail(101 'Could not find a single interface '102 'with an IPv6 link-local address.')103 return interface104 @testtools.skipUnless(105 CONF.neutron_plugin_options.advanced_image_ref or106 CONF.neutron_plugin_options.default_image_is_advanced,107 'Advanced image is required to run this test.')108 @decorators.idempotent_id('e680949a-f1cc-11ea-b49a-cba39bbbe5ad')109 def test_metadata_routed(self):110 use_advanced_image = (111 not CONF.neutron_plugin_options.default_image_is_advanced)112 vm = self._create_server_with_network(113 self.network, use_advanced_image=use_advanced_image)114 self.wait_for_server_active(server=vm.server)115 self.wait_for_guest_os_ready(vm.server)116 self.check_connectivity(host=vm.floating_ip['floating_ip_address'],117 ssh_client=vm.ssh_client)118 interface = self._get_primary_interface(vm.ssh_client)119 try:120 out = vm.ssh_client.exec_command(121 'curl http://[%(address)s%%25%(interface)s]/' % {122 'address': nlib_const.METADATA_V6_IP,123 'interface': interface})124 self.assertIn('latest', out)125 out = vm.ssh_client.exec_command(126 'curl http://[%(address)s%%25%(interface)s]/openstack/' % {127 'address': nlib_const.METADATA_V6_IP,128 'interface': interface})129 self.assertIn('latest', out)130 except exceptions.SSHExecCommandFailed:131 self._log_console_output()...

Full Screen

Full Screen

test_server_basic_ops.py

Source:test_server_basic_ops.py Github

copy

Full Screen

...9 super(TestServerBasicOps, self).setUp()10 11 @test.attr(type='smoke')12 @test.services('compute', 'network')13 def test_server_basic_ops(self):14 self.add_keypair()15 self.security_group = self._create_security_group()16 self.boot_instance()17 nuage_ext.nuage_extension.nuage_components(18 nuage_ext._generate_tag('verify_vm', self.__class__.__name__)) ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful