Reworked scenario tests to use their own non-default security groups
Moved _create_security_group_nova to base OfficialClientTest class, so that now it can be used by all scenario tests. All scenario tests now create security group with "loginable" rules explicitly and attach it to servers instead of using "default" security group. Change-Id: If82c681b4a7f62808f46b03c57d113f8f5c97f6f Closes-Bug: #1247060
This commit is contained in:
parent
1c1eb999ec
commit
0f1e11c1ef
|
@ -283,6 +283,23 @@ class OfficialClientTest(tempest.test.BaseTestCase):
|
|||
rules.append(sg_rule)
|
||||
return rules
|
||||
|
||||
def _create_security_group_nova(self, client=None,
|
||||
namestart='secgroup-smoke-'):
|
||||
if client is None:
|
||||
client = self.compute_client
|
||||
# Create security group
|
||||
sg_name = data_utils.rand_name(namestart)
|
||||
sg_desc = sg_name + " description"
|
||||
secgroup = client.security_groups.create(sg_name, sg_desc)
|
||||
self.assertEqual(secgroup.name, sg_name)
|
||||
self.assertEqual(secgroup.description, sg_desc)
|
||||
self.set_resource(sg_name, secgroup)
|
||||
|
||||
# Add rules to the security group
|
||||
self._create_loginable_secgroup_rule_nova(client, secgroup.id)
|
||||
|
||||
return secgroup
|
||||
|
||||
def create_server(self, client=None, name=None, image=None, flavor=None,
|
||||
wait=True, create_kwargs={}):
|
||||
if client is None:
|
||||
|
@ -798,24 +815,6 @@ class NetworkScenarioTest(OfficialClientTest):
|
|||
CONF.compute.ping_timeout,
|
||||
1)
|
||||
|
||||
def _create_security_group_nova(self, client=None,
|
||||
namestart='secgroup-smoke-',
|
||||
tenant_id=None):
|
||||
if client is None:
|
||||
client = self.compute_client
|
||||
# Create security group
|
||||
sg_name = data_utils.rand_name(namestart)
|
||||
sg_desc = sg_name + " description"
|
||||
secgroup = client.security_groups.create(sg_name, sg_desc)
|
||||
self.assertEqual(secgroup.name, sg_name)
|
||||
self.assertEqual(secgroup.description, sg_desc)
|
||||
self.set_resource(sg_name, secgroup)
|
||||
|
||||
# Add rules to the security group
|
||||
self._create_loginable_secgroup_rule_nova(client, secgroup.id)
|
||||
|
||||
return secgroup
|
||||
|
||||
def _create_security_group_neutron(self, tenant_id, client=None,
|
||||
namestart='secgroup-smoke-'):
|
||||
if client is None:
|
||||
|
|
|
@ -112,6 +112,11 @@ class TestMinimumBasicScenario(manager.OfficialClientTest):
|
|||
volume = self.volume_client.volumes.get(self.volume.id)
|
||||
self.assertEqual('available', volume.status)
|
||||
|
||||
def create_and_add_security_group(self):
|
||||
secgroup = self._create_security_group_nova()
|
||||
self.server.add_security_group(secgroup.name)
|
||||
self.addCleanup(self.server.remove_security_group, secgroup.name)
|
||||
|
||||
@test.services('compute', 'volume', 'image', 'network')
|
||||
def test_minimum_basic_scenario(self):
|
||||
self.glance_image_create()
|
||||
|
@ -128,7 +133,7 @@ class TestMinimumBasicScenario(manager.OfficialClientTest):
|
|||
|
||||
self.nova_floating_ip_create()
|
||||
self.nova_floating_ip_add()
|
||||
self._create_loginable_secgroup_rule_nova()
|
||||
self.create_and_add_security_group()
|
||||
self.ssh_to_server()
|
||||
self.nova_reboot()
|
||||
self.ssh_to_server()
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest import config
|
||||
from tempest.openstack.common import log as logging
|
||||
from tempest.scenario import manager
|
||||
|
@ -68,22 +67,12 @@ class TestServerBasicOps(manager.OfficialClientTest):
|
|||
def add_keypair(self):
|
||||
self.keypair = self.create_keypair()
|
||||
|
||||
def create_security_group(self):
|
||||
sg_name = data_utils.rand_name('secgroup-smoke')
|
||||
sg_desc = sg_name + " description"
|
||||
self.secgroup = self.compute_client.security_groups.create(sg_name,
|
||||
sg_desc)
|
||||
self.assertEqual(self.secgroup.name, sg_name)
|
||||
self.assertEqual(self.secgroup.description, sg_desc)
|
||||
self.set_resource('secgroup', self.secgroup)
|
||||
|
||||
# Add rules to the security group
|
||||
self._create_loginable_secgroup_rule_nova(secgroup_id=self.secgroup.id)
|
||||
|
||||
def boot_instance(self):
|
||||
# Create server with image and flavor from input scenario
|
||||
security_groups = [self.security_group.name]
|
||||
create_kwargs = {
|
||||
'key_name': self.keypair.id
|
||||
'key_name': self.keypair.id,
|
||||
'security_groups': security_groups
|
||||
}
|
||||
instance = self.create_server(image=self.image_ref,
|
||||
flavor=self.flavor_ref,
|
||||
|
@ -117,7 +106,7 @@ class TestServerBasicOps(manager.OfficialClientTest):
|
|||
@test.services('compute', 'network')
|
||||
def test_server_basicops(self):
|
||||
self.add_keypair()
|
||||
self.create_security_group()
|
||||
self.security_group = self._create_security_group_nova()
|
||||
self.boot_instance()
|
||||
self.verify_ssh()
|
||||
self.terminate_instance()
|
||||
|
|
|
@ -35,8 +35,10 @@ class TestSnapshotPattern(manager.OfficialClientTest):
|
|||
"""
|
||||
|
||||
def _boot_image(self, image_id):
|
||||
security_groups = [self.security_group.name]
|
||||
create_kwargs = {
|
||||
'key_name': self.keypair.name
|
||||
'key_name': self.keypair.name,
|
||||
'security_groups': security_groups
|
||||
}
|
||||
return self.create_server(image=image_id, create_kwargs=create_kwargs)
|
||||
|
||||
|
@ -72,7 +74,7 @@ class TestSnapshotPattern(manager.OfficialClientTest):
|
|||
def test_snapshot_pattern(self):
|
||||
# prepare for booting a instance
|
||||
self._add_keypair()
|
||||
self._create_loginable_secgroup_rule_nova()
|
||||
self.security_group = self._create_security_group_nova()
|
||||
|
||||
# boot a instance and create a timestamp file in it
|
||||
server = self._boot_image(CONF.compute.image_ref)
|
||||
|
|
|
@ -62,8 +62,10 @@ class TestStampPattern(manager.OfficialClientTest):
|
|||
volume_snapshot.id, status)
|
||||
|
||||
def _boot_image(self, image_id):
|
||||
security_groups = [self.security_group.name]
|
||||
create_kwargs = {
|
||||
'key_name': self.keypair.name
|
||||
'key_name': self.keypair.name,
|
||||
'security_groups': security_groups
|
||||
}
|
||||
return self.create_server(image=image_id, create_kwargs=create_kwargs)
|
||||
|
||||
|
@ -152,7 +154,7 @@ class TestStampPattern(manager.OfficialClientTest):
|
|||
def test_stamp_pattern(self):
|
||||
# prepare for booting a instance
|
||||
self._add_keypair()
|
||||
self._create_loginable_secgroup_rule_nova()
|
||||
self.security_group = self._create_security_group_nova()
|
||||
|
||||
# boot an instance and create a timestamp file in it
|
||||
volume = self._create_volume()
|
||||
|
|
|
@ -55,9 +55,11 @@ class TestVolumeBootPattern(manager.OfficialClientTest):
|
|||
bd_map = {
|
||||
'vda': vol_id + ':::0'
|
||||
}
|
||||
security_groups = [self.security_group.name]
|
||||
create_kwargs = {
|
||||
'block_device_mapping': bd_map,
|
||||
'key_name': keypair.name
|
||||
'key_name': keypair.name,
|
||||
'security_groups': security_groups
|
||||
}
|
||||
return self.create_server(image='', create_kwargs=create_kwargs)
|
||||
|
||||
|
@ -135,7 +137,7 @@ class TestVolumeBootPattern(manager.OfficialClientTest):
|
|||
@test.services('compute', 'volume', 'image')
|
||||
def test_volume_boot_pattern(self):
|
||||
keypair = self.create_keypair()
|
||||
self._create_loginable_secgroup_rule_nova()
|
||||
self.security_group = self._create_security_group_nova()
|
||||
|
||||
# create an instance from volume
|
||||
volume_origin = self._create_volume_from_image()
|
||||
|
@ -182,8 +184,10 @@ class TestVolumeBootPatternV2(TestVolumeBootPattern):
|
|||
bdms = [{'uuid': vol_id, 'source_type': 'volume',
|
||||
'destination_type': 'volume', 'boot_index': 0,
|
||||
'delete_on_termination': False}]
|
||||
security_groups = [self.security_group.name]
|
||||
create_kwargs = {
|
||||
'block_device_mapping_v2': bdms,
|
||||
'key_name': keypair.name
|
||||
'key_name': keypair.name,
|
||||
'security_groups': security_groups
|
||||
}
|
||||
return self.create_server(image='', create_kwargs=create_kwargs)
|
||||
|
|
Loading…
Reference in New Issue