Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use post init workflow. #261

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 13 additions & 70 deletions img_proof/ipa_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,76 +35,18 @@

class AzureCloud(IpaCloud):
"""Class for testing instances in Azure."""
cloud = 'azure'

def __init__(
self,
accelerated_networking=False,
cleanup=None,
config=None,
description=None,
distro_name=None,
early_exit=None,
history_log=None,
image_id=None,
inject=None,
instance_type=None,
log_level=None,
no_default_test_dirs=None,
cloud_config=None,
region=None,
results_dir=None,
running_instance_id=None,
service_account_file=None,
ssh_private_key_file=None,
ssh_user=None,
subnet_id=None,
test_dirs=None,
test_files=None,
timeout=None,
vnet_name=None,
vnet_resource_group=None,
collect_vm_info=None,
enable_secure_boot=None,
enable_uefi=None,
log_callback=None,
prefix_name=None,
retry_count=None
):
"""Initialize Azure Cloud class."""
super(AzureCloud, self).__init__(
'azure',
cleanup,
config,
description,
distro_name,
early_exit,
history_log,
image_id,
inject,
instance_type,
log_level,
no_default_test_dirs,
cloud_config,
region,
results_dir,
running_instance_id,
test_dirs,
test_files,
timeout,
collect_vm_info,
ssh_private_key_file,
ssh_user,
subnet_id,
enable_secure_boot,
enable_uefi,
log_callback,
prefix_name,
retry_count
)
def post_init(self):
"""Initialize Azure cloud framework class."""

self.vnet_name = vnet_name or self.ipa_config['vnet_name']
self.vnet_name = (
self.custom_args.get('vnet_name')
or self.ipa_config['vnet_name']
)
self.vnet_resource_group = (
vnet_resource_group or self.ipa_config['vnet_resource_group']
self.custom_args.get('vnet_resource_group')
or self.ipa_config['vnet_resource_group']
)

subnet_args = [
Expand All @@ -117,7 +59,8 @@ def __init__(
)

self.service_account_file = (
service_account_file or self.ipa_config['service_account_file']
self.custom_args.get('service_account_file')
or self.ipa_config['service_account_file']
)
if not self.service_account_file:
raise AzureCloudException(
Expand All @@ -134,8 +77,8 @@ def __init__(
)

self.accelerated_networking = (
accelerated_networking or
self.ipa_config['accelerated_networking']
self.custom_args.get('accelerated_networking')
or self.ipa_config['accelerated_networking']
)
self.ssh_user = self.ssh_user or AZURE_DEFAULT_USER
self.ssh_public_key = self._get_ssh_public_key()
Expand Down
11 changes: 8 additions & 3 deletions img_proof/ipa_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class IpaCloud(object):
modules extend the base class and implement cloud
specific methods for launching and managing instances.
"""
cloud = 'base'

def __init__(
self,
cloud,
cleanup=None,
config=None,
description=None,
Expand All @@ -103,7 +103,8 @@ def __init__(
enable_uefi=None,
log_callback=None,
prefix_name=None,
retry_count=None
retry_count=None,
custom_args=None
):
"""Initialize base cloud framework class."""
super(IpaCloud, self).__init__()
Expand All @@ -112,7 +113,7 @@ def __init__(

ipa_utils.clear_cache()

self.cloud = cloud
self.custom_args = custom_args if custom_args else {}
self.host_key_fingerprint = None
self.instance_ip = None

Expand Down Expand Up @@ -204,6 +205,10 @@ def __init__(
}

self._parse_test_files(test_dirs, self.no_default_test_dirs)
self.post_init()

def post_init(self):
pass

def _get_instance(self):
raise NotImplementedError(NOT_IMPLEMENTED)
Expand Down
64 changes: 31 additions & 33 deletions img_proof/ipa_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,43 +116,41 @@ def test_image(

cloud_name = cloud_name.lower()
if cloud_name == 'azure':
cloud = AzureCloud(
accelerated_networking=accelerated_networking,
service_account_file=service_account_file,
vnet_name=vnet_name,
vnet_resource_group=vnet_resource_group,
**kwargs
)
kwargs['custom_args'] = {
'accelerated_networking': accelerated_networking,
'service_account_file': service_account_file,
'vnet_name': vnet_name,
'vnet_resource_group': vnet_resource_group
}
cloud = AzureCloud(**kwargs)
elif cloud_name == 'ec2':
cloud = EC2Cloud(
access_key_id=access_key_id,
account_name=account,
secret_access_key=secret_access_key,
security_group_id=security_group_id,
ssh_key_name=ssh_key_name,
**kwargs
)
kwargs['custom_args'] = {
'access_key_id': access_key_id,
'account_name': account,
'secret_access_key': secret_access_key,
'security_group_id': security_group_id,
'ssh_key_name': ssh_key_name
}
cloud = EC2Cloud(**kwargs)
elif cloud_name == 'gce':
cloud = GCECloud(
service_account_file=service_account_file,
image_project=image_project,
**kwargs
)
kwargs['custom_args'] = {
'service_account_file': service_account_file,
'image_project': image_project
}
cloud = GCECloud(**kwargs)
elif cloud_name == 'ssh':
cloud = SSHCloud(
ip_address=ip_address,
**kwargs
)
kwargs['custom_args'] = {'ip_address': ip_address}
cloud = SSHCloud(**kwargs)
elif cloud_name == 'oci':
cloud = OCICloud(
compartment_id=compartment_id,
availability_domain=availability_domain,
signing_key_fingerprint=signing_key_fingerprint,
signing_key_file=signing_key_file,
tenancy=tenancy,
oci_user_id=oci_user_id,
**kwargs
)
kwargs['custom_args'] = {
'compartment_id': compartment_id,
'availability_domain': availability_domain,
'signing_key_fingerprint': signing_key_fingerprint,
'signing_key_file': signing_key_file,
'tenancy': tenancy,
'oci_user_id': oci_user_id
}
cloud = OCICloud(**kwargs)
else:
raise IpaControllerException(
'Cloud framework: %s unavailable.' % cloud_name
Expand Down
72 changes: 5 additions & 67 deletions img_proof/ipa_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,78 +38,16 @@

class EC2Cloud(IpaCloud):
"""Cloud framework class for testing AWS EC2 images."""
cloud = 'ec2'

def __init__(
self,
access_key_id=None,
account_name=None,
cleanup=None,
config=None,
description=None,
distro_name=None,
early_exit=None,
history_log=None,
image_id=None,
inject=None,
instance_type=None,
log_level=None,
no_default_test_dirs=None,
cloud_config=None,
region=None,
results_dir=None,
running_instance_id=None,
secret_access_key=None,
security_group_id=None,
ssh_key_name=None,
ssh_private_key_file=None,
ssh_user=None,
subnet_id=None,
test_dirs=None,
test_files=None,
timeout=None,
collect_vm_info=None,
enable_secure_boot=None,
enable_uefi=None,
log_callback=None,
prefix_name=None,
retry_count=None
):
def post_init(self):
"""Initialize EC2 cloud framework class."""
super(EC2Cloud, self).__init__(
'ec2',
cleanup,
config,
description,
distro_name,
early_exit,
history_log,
image_id,
inject,
instance_type,
log_level,
no_default_test_dirs,
cloud_config,
region,
results_dir,
running_instance_id,
test_dirs,
test_files,
timeout,
collect_vm_info,
ssh_private_key_file,
ssh_user,
subnet_id,
enable_secure_boot,
enable_uefi,
log_callback,
prefix_name,
retry_count
)

# Get command line values that are not None
cmd_line_values = self._get_non_null_values(locals())
cmd_line_values = self._get_non_null_values(self.custom_args)

self.zone = None
self.account_name = account_name
self.account_name = self.custom_args.get('account_name')

if not self.account_name:
self.logger.debug(
Expand Down
69 changes: 5 additions & 64 deletions img_proof/ipa_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,72 +81,13 @@ class GCECloud(IpaCloud):
"""
Cloud framework class for testing Google Compute Engine (GCE) images.
"""
cloud = 'gce'

def __init__(
self,
cleanup=None,
config=None,
description=None,
distro_name=None,
early_exit=None,
history_log=None,
image_id=None,
inject=None,
instance_type=None,
log_level=None,
no_default_test_dirs=None,
cloud_config=None,
region=None,
results_dir=None,
running_instance_id=None,
service_account_file=None,
ssh_private_key_file=None,
ssh_user=None,
subnet_id=None,
test_dirs=None,
test_files=None,
timeout=None,
collect_vm_info=None,
image_project=None,
enable_secure_boot=None,
enable_uefi=None,
log_callback=None,
prefix_name=None,
retry_count=None
):
super(GCECloud, self).__init__(
'gce',
cleanup,
config,
description,
distro_name,
early_exit,
history_log,
image_id,
inject,
instance_type,
log_level,
no_default_test_dirs,
cloud_config,
region,
results_dir,
running_instance_id,
test_dirs,
test_files,
timeout,
collect_vm_info,
ssh_private_key_file,
ssh_user,
subnet_id,
enable_secure_boot,
enable_uefi,
log_callback,
prefix_name,
retry_count
)
def post_init(self):
"""Initialize EC2 cloud framework class."""

self.service_account_file = (
service_account_file or
self.custom_args.get('service_account_file') or
self.ipa_config['service_account_file']
)
if not self.service_account_file:
Expand All @@ -165,7 +106,7 @@ def __init__(

self.ssh_user = self.ssh_user or GCE_DEFAULT_USER
self.ssh_public_key = self._get_ssh_public_key()
self.image_project = image_project
self.image_project = self.custom_args.get('image_project')

self.credentials = self._get_credentials()
self.compute_driver = self._get_driver()
Expand Down
Loading