Changes added to ssh into the server using key
Change-Id: I9fef4a90ffd68bb35c19d1935af3aaa12b4e608e
This commit is contained in:
parent
1d54612c04
commit
78f53d8f32
@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
from qe_coverage.opencafe_decorators import tags
|
||||
from qe_coverage.opencafe_decorators import tags, unless_coverage
|
||||
|
||||
from cafe.drivers.unittest.decorators import (
|
||||
data_driven_test, DataDrivenFixture)
|
||||
@ -28,6 +28,14 @@ from cloudroast.blockstorage.volumes_api.integration.compute.datasets \
|
||||
@DataDrivenFixture
|
||||
class BootFromVolumeIntegrationTests(ComputeIntegrationTestFixture):
|
||||
|
||||
@unless_coverage
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(BootFromVolumeIntegrationTests, cls).setUpClass()
|
||||
cls.key = cls.keypairs_client.create_keypair(
|
||||
random_string("test_key")).entity
|
||||
cls.addClassCleanup(cls.keypairs_client.delete_keypair, cls.key.name)
|
||||
|
||||
@tags('positive', 'integration')
|
||||
@data_driven_test(bfv_datasets.images)
|
||||
def ddtest_non_asserting_min_disk_check_for_image(self, image):
|
||||
@ -80,10 +88,11 @@ class BootFromVolumeIntegrationTests(ComputeIntegrationTestFixture):
|
||||
# Boot a server from the volume
|
||||
server = self.servers.behaviors.create_active_server(
|
||||
name=self.random_server_name(), flavor_ref=flavor.id,
|
||||
block_device_mapping=bdm).entity
|
||||
key_name=self.key.name, block_device_mapping=bdm).entity
|
||||
|
||||
# Connect to server
|
||||
self.server_conn = self.connect_to_instance(server, os_type=os_type)
|
||||
self.server_conn = self.get_remote_instance_client(
|
||||
server, key=self.key.private_key)
|
||||
|
||||
# Write data to the root disk
|
||||
resp = self.server_conn.create_large_file(multiplier=0.1)
|
||||
@ -99,11 +108,11 @@ class BootFromVolumeIntegrationTests(ComputeIntegrationTestFixture):
|
||||
# Create a server
|
||||
original_server = self.new_server(
|
||||
name=self.random_server_name(), image=image.id, flavor=flavor.id,
|
||||
add_cleanup=False)
|
||||
key_name=self.key.name, add_cleanup=False)
|
||||
|
||||
# Connect to server
|
||||
original_server_connection = self.connect_to_instance(
|
||||
original_server)
|
||||
original_server_connection = self.get_remote_instance_client(
|
||||
original_server, key=self.key.private_key)
|
||||
|
||||
# Write data to the root disk
|
||||
file_name = random_string("original_data")
|
||||
@ -131,7 +140,7 @@ class BootFromVolumeIntegrationTests(ComputeIntegrationTestFixture):
|
||||
# Boot a server from the volume
|
||||
new_bfv_server = self.servers.behaviors.create_active_server(
|
||||
name=self.random_server_name(), flavor_ref=flavor.id,
|
||||
block_device_mapping=bdm).entity
|
||||
key_name=self.key.name, block_device_mapping=bdm).entity
|
||||
|
||||
assert new_bfv_server is not None, (
|
||||
"Unable to build a server from volume '{volume}' and flavor "
|
||||
@ -139,8 +148,8 @@ class BootFromVolumeIntegrationTests(ComputeIntegrationTestFixture):
|
||||
volume=bootable_volume.id_, flavor=flavor.id, bdm=bdm))
|
||||
|
||||
# Setup remote instance client
|
||||
new_bfv_server_conn = self.connect_to_instance(
|
||||
new_bfv_server, os_type='linux')
|
||||
new_bfv_server_conn = self.get_remote_instance_client(
|
||||
new_bfv_server, key=self.key.private_key)
|
||||
|
||||
# Get hash of remote file
|
||||
restored_hash = self.get_remote_file_md5_hash(
|
||||
@ -149,3 +158,8 @@ class BootFromVolumeIntegrationTests(ComputeIntegrationTestFixture):
|
||||
assert original_hash == restored_hash, (
|
||||
'Restored data hash "{0}" did not match original data hash "{1}"'
|
||||
.format(restored_hash, original_hash))
|
||||
|
||||
@unless_coverage
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(BootFromVolumeIntegrationTests, cls).tearDownClass()
|
||||
|
@ -15,8 +15,11 @@ limitations under the License.
|
||||
"""
|
||||
|
||||
from cloudcafe.common.tools.datagen import random_string
|
||||
from cloudcafe.compute.common.types import InstanceAuthStrategies
|
||||
from cloudcafe.compute.composites import ComputeIntegrationComposite
|
||||
from cloudroast.blockstorage.volumes_api.fixtures import VolumesTestFixture
|
||||
from cloudcafe.compute.common.exceptions import TimeoutException, \
|
||||
SshConnectionException
|
||||
|
||||
|
||||
class ComputeIntegrationTestFixture(VolumesTestFixture):
|
||||
@ -31,20 +34,21 @@ class ComputeIntegrationTestFixture(VolumesTestFixture):
|
||||
cls.flavors = cls.compute.flavors
|
||||
cls.images = cls.compute.images
|
||||
cls.volume_attachments = cls.compute.volume_attachments
|
||||
cls.keypairs_client = cls.compute.keypairs.client
|
||||
|
||||
@classmethod
|
||||
def random_server_name(cls):
|
||||
return random_string(prefix="Server_", size=10)
|
||||
|
||||
@classmethod
|
||||
def new_server(
|
||||
cls, name=None, image=None, flavor=None, add_cleanup=True):
|
||||
def new_server(cls, name=None, image=None, flavor=None,
|
||||
key_name=None, add_cleanup=True):
|
||||
|
||||
name = name or cls.random_server_name()
|
||||
image = image or cls.images.config.primary_image
|
||||
flavor = flavor or cls.flavors.config.primary_flavor
|
||||
resp = cls.servers.behaviors.create_active_server(
|
||||
name, image_ref=image, flavor_ref=flavor)
|
||||
name, image_ref=image, flavor_ref=flavor, key_name=key_name)
|
||||
|
||||
if add_cleanup:
|
||||
cls.addClassCleanup(
|
||||
@ -154,6 +158,70 @@ class ComputeIntegrationTestFixture(VolumesTestFixture):
|
||||
|
||||
return client
|
||||
|
||||
@classmethod
|
||||
def get_remote_instance_client(cls, server, config=None, ip_address=None,
|
||||
username=None, password=None, key=None,
|
||||
auth_strategy=None):
|
||||
"""
|
||||
@summary: Gets an client of the server
|
||||
@param server: Instance uuid id of the server
|
||||
@type server: String
|
||||
@param ip_address: IPv4 address of the server
|
||||
@type ip_address: String
|
||||
@param username: Valid user of the server
|
||||
@type username: String
|
||||
@param password: Valid user password of the server
|
||||
@type password: String
|
||||
@return: Either IPv4 or IPv6 address of instance
|
||||
@rtype: String
|
||||
"""
|
||||
if ip_address is None:
|
||||
if hasattr(server, 'accessIPv4'):
|
||||
ip_address = server.accessIPv4
|
||||
else:
|
||||
ip_address = server.addresses.public.ipv4
|
||||
|
||||
# Get Server Image ID
|
||||
if server.image:
|
||||
image_id = server.image.id
|
||||
else:
|
||||
image_id = cls.images.config.primary_image
|
||||
|
||||
# Get the Server Image
|
||||
image = cls.images.client.get_image(image_id).entity
|
||||
|
||||
client = cls._get_remote_client(image.metadata.get('os_type', '').lower())
|
||||
user = username or cls.images.config.primary_image_default_user
|
||||
cls.fixture_log.debug("username: {username}".format(username=user))
|
||||
cls.fixture_log.debug("key: {key}".format(key=key))
|
||||
strategy = auth_strategy or cls.servers.config.instance_auth_strategy.lower()
|
||||
|
||||
try:
|
||||
if InstanceAuthStrategies.PASSWORD in strategy:
|
||||
if password is None:
|
||||
password = server.admin_pass
|
||||
return client(
|
||||
ip_address=ip_address, username=user, password=password,
|
||||
connection_timeout=cls.servers.config.connection_timeout)
|
||||
else:
|
||||
return client(
|
||||
ip_address=ip_address, username=user, key=key,
|
||||
connection_timeout=cls.servers.config.connection_timeout)
|
||||
except TimeoutException:
|
||||
raise TimeoutException(
|
||||
'Unable to ping server {id} at address {address} '
|
||||
'within the allowed time of {timeout} seconds. '
|
||||
'Test unable to proceed.'.format(
|
||||
id=server.id, address=ip_address,
|
||||
timeout=cls.servers.config.connection_timeout))
|
||||
except SshConnectionException:
|
||||
raise SshConnectionException(
|
||||
'Able to ping server {id} at {address}, but unable to '
|
||||
'connect via ssh within the allowed time of {timeout} '
|
||||
'seconds. Test unable to proceed.'.format(
|
||||
id=server.id, address=ip_address,
|
||||
timeout=cls.servers.config.connection_timeout))
|
||||
|
||||
@classmethod
|
||||
def _connect(
|
||||
cls, remote_client, ip_address=None, username=None,
|
||||
@ -231,10 +299,11 @@ class ComputeIntegrationTestFixture(VolumesTestFixture):
|
||||
"""
|
||||
|
||||
# Build new server using configured defaults
|
||||
cls.test_server = server or cls.new_server()
|
||||
cls.test_server = server or cls.new_server(key_name=cls.key.name)
|
||||
|
||||
# Set remote instance client up
|
||||
cls.server_conn = cls.connect_to_instance(cls.test_server)
|
||||
cls.server_conn = cls.get_remote_instance_client(
|
||||
cls.test_server, key=cls.key.private_key)
|
||||
cls.volume_mount_point = cls.server_conn.generate_mountpoint()
|
||||
cls.test_volume = volume or cls.new_volume()
|
||||
|
||||
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
from qe_coverage.opencafe_decorators import tags, unless_coverage
|
||||
from cloudcafe.common.tools.datagen import rand_name
|
||||
|
||||
from cloudroast.blockstorage.volumes_api.integration.compute.fixtures import \
|
||||
ComputeIntegrationTestFixture
|
||||
@ -25,7 +26,10 @@ class VolumeCloningIntegrationSmokeTests(ComputeIntegrationTestFixture):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(VolumeCloningIntegrationSmokeTests, cls).setUpClass()
|
||||
cls.key = \
|
||||
cls.keypairs_client.create_keypair(rand_name("test_key")).entity
|
||||
cls.setup_server_and_attached_volume_with_data()
|
||||
cls.addClassCleanup(cls.keypairs_client.delete_keypair, cls.key.name)
|
||||
|
||||
@unless_coverage
|
||||
def setUp(self):
|
||||
@ -49,7 +53,8 @@ class VolumeCloningIntegrationSmokeTests(ComputeIntegrationTestFixture):
|
||||
assert self.volume_clone is not None, "Unable to clone volume"
|
||||
|
||||
# Re-connect to server to prevent timeout issues
|
||||
self.server_conn = self.connect_to_instance(self.test_server)
|
||||
self.server_conn = self.get_remote_instance_client(
|
||||
self.test_server, key=self.key.private_key)
|
||||
|
||||
# Attach clone to server(self):
|
||||
self.clone_attachment = self.attach_volume_and_get_device_info(
|
||||
|
@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
from qe_coverage.opencafe_decorators import tags, unless_coverage
|
||||
|
||||
from cafe.drivers.unittest.suite import OpenCafeUnittestTestSuite
|
||||
from cloudcafe.common.tools.datagen import rand_name
|
||||
from cloudroast.blockstorage.volumes_api.integration.compute.fixtures \
|
||||
import ComputeIntegrationTestFixture
|
||||
|
||||
@ -41,11 +41,14 @@ class VolumeIntegrationSmokeTests(ComputeIntegrationTestFixture):
|
||||
def setUpClass(cls):
|
||||
super(VolumeIntegrationSmokeTests, cls).setUpClass()
|
||||
|
||||
cls.key = cls.keypairs_client.create_keypair(
|
||||
rand_name("test_key")).entity
|
||||
# BUILD NEW SERVER FROM CONFIG
|
||||
cls.test_server = cls.new_server(add_cleanup=True)
|
||||
cls.test_server = cls.new_server(key_name=cls.key.name, add_cleanup=True)
|
||||
|
||||
# Setup remote instance client
|
||||
cls.server_conn = cls.connect_to_instance(cls.test_server)
|
||||
cls.server_conn = cls.get_remote_instance_client(
|
||||
cls.test_server, key=cls.key.private_key)
|
||||
cls.volume_mount_point = cls.server_conn.generate_mountpoint()
|
||||
cls.test_volume = cls.new_volume()
|
||||
cls.test_attachment = cls.attach_volume_and_get_device_info(
|
||||
@ -54,6 +57,7 @@ class VolumeIntegrationSmokeTests(ComputeIntegrationTestFixture):
|
||||
cls.addClassCleanup(
|
||||
cls.volume_attachments.behaviors.delete_volume_attachment,
|
||||
cls.test_attachment.id_, cls.test_server.id)
|
||||
cls.addClassCleanup(cls.keypairs_client.delete_keypair, cls.key.name)
|
||||
|
||||
@unless_coverage
|
||||
def setUp(self):
|
||||
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||
import time
|
||||
|
||||
from qe_coverage.opencafe_decorators import tags, unless_coverage
|
||||
from cloudcafe.common.tools.datagen import rand_name
|
||||
|
||||
from cloudroast.blockstorage.volumes_api.integration.compute.fixtures \
|
||||
import ComputeIntegrationTestFixture
|
||||
@ -28,15 +29,20 @@ class VolumeSnapshotIntegrationSmokeTests(ComputeIntegrationTestFixture):
|
||||
def setUpClass(cls):
|
||||
super(VolumeSnapshotIntegrationSmokeTests, cls).setUpClass()
|
||||
|
||||
cls.key = \
|
||||
cls.keypairs_client.create_keypair(rand_name("test_key")).entity
|
||||
|
||||
# Build new server using configured defaults
|
||||
cls.test_server = cls.new_server(add_cleanup=True)
|
||||
cls.test_server = cls.new_server(key_name=cls.key.name, add_cleanup=True)
|
||||
|
||||
# Set remote instance client up
|
||||
cls.server_conn = cls.connect_to_instance(cls.test_server)
|
||||
cls.server_conn = cls.get_remote_instance_client(
|
||||
cls.test_server, key=cls.key.private_key)
|
||||
cls.volume_mount_point = cls.server_conn.generate_mountpoint()
|
||||
cls.test_volume = cls.new_volume()
|
||||
cls.test_attachment = cls.attach_volume_and_get_device_info(
|
||||
cls.server_conn, cls.test_server.id, cls.test_volume.id_)
|
||||
cls.addClassCleanup(cls.keypairs_client.delete_keypair, cls.key.name)
|
||||
|
||||
@unless_coverage
|
||||
def setUp(self):
|
||||
@ -136,7 +142,8 @@ class VolumeSnapshotIntegrationSmokeTests(ComputeIntegrationTestFixture):
|
||||
self.test_snapshot.id_)
|
||||
|
||||
# Re-connect to server to prevent timeout issues
|
||||
self.server_conn = self.connect_to_instance(self.test_server)
|
||||
self.server_conn = self.get_remote_instance_client(
|
||||
self.test_server, key=self.key.private_key)
|
||||
|
||||
# Restore snapshot to new volume
|
||||
self.restored_snapshot_volume = \
|
||||
|
Loading…
x
Reference in New Issue
Block a user