-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add inject option for ipa testing. #78
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ def __init__(self, | |
early_exit=None, | ||
history_log=None, | ||
image_id=None, | ||
inject=None, | ||
instance_type=None, | ||
log_level=None, | ||
no_default_test_dirs=False, | ||
|
@@ -102,6 +103,7 @@ def __init__(self, | |
self.distro_name = self._get_value(distro_name) | ||
self.early_exit = self._get_value(early_exit) | ||
self.image_id = self._get_value(image_id) | ||
self.inject = self._get_value(inject) | ||
self.instance_type = self._get_value(instance_type) | ||
self.running_instance_id = self._get_value(running_instance_id) | ||
self.test_files = list(self._get_value(test_files, default=[])) | ||
|
@@ -447,6 +449,71 @@ def install_package(self, client, package): | |
log_file.write('\n') | ||
log_file.write(out) | ||
|
||
def process_injection_file(self, client): | ||
""" | ||
Load yaml file and process injection configuration. | ||
There are 5 injection options: | ||
:inject_packages: an rpm path or list of rpm paths which will be | ||
copied and installed on instance. | ||
:inject_archives: an archive or list of archives which will | ||
be copied and extracted on instance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dito |
||
:inject_files: a file path or list of file paths which | ||
will be copied to instance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dito |
||
:execute: a command or list of commands to run. | ||
:install: a package name or list of package names to | ||
install from an existing repo. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the order of processing to the doc string |
||
""" | ||
configuration = ipa_utils.get_yaml_config(self.inject) | ||
|
||
if configuration.get('inject_packages'): | ||
inject_packages = configuration['inject_packages'] | ||
|
||
if not isinstance(inject_packages, list): | ||
inject_packages = [inject_packages] | ||
|
||
for package in inject_packages: | ||
package_path = self.put_file(client, package) | ||
self.install_package(client, package_path) | ||
|
||
if configuration.get('inject_archives'): | ||
inject_archives = configuration['inject_archives'] | ||
|
||
if not isinstance(inject_archives, list): | ||
inject_archives = [inject_archives] | ||
|
||
for archive in inject_archives: | ||
archive_path = self.put_file(client, archive) | ||
self.extract_archive(client, archive_path) | ||
|
||
if configuration.get('inject_files'): | ||
inject_files = configuration['inject_files'] | ||
|
||
if not isinstance(inject_files, list): | ||
inject_files = [inject_files] | ||
|
||
for file_path in inject_files: | ||
self.put_file(client, file_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One could, and some people will argue that packages and tar archives are files as well. I am OK leaving this option as if one want to inject a config file that effects a package forcing them to create an archive is silly and it saves us the logic of having to determine file types for certain operation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah "put" is the first step to injecting a package and an archive. So exposing it independently I think is nice. I.e. like your example to copy a single file. |
||
|
||
if configuration.get('execute'): | ||
execute = configuration['execute'] | ||
|
||
if not isinstance(execute, list): | ||
execute = [execute] | ||
|
||
for command in execute: | ||
self.execute_ssh_command(client, command) | ||
|
||
if configuration.get('install'): | ||
install = configuration['install'] | ||
|
||
if not isinstance(install, list): | ||
install = [install] | ||
|
||
for package in install: | ||
self.install_package(client, package) | ||
|
||
def put_file(self, client, source_file): | ||
""" | ||
Put file on instance in default SSH directory. | ||
|
@@ -507,6 +574,9 @@ def test_image(self): | |
self._set_distro() | ||
self._log_info() | ||
|
||
if self.inject: | ||
self.process_injection_file(self._get_ssh_client()) | ||
|
||
status = 0 | ||
with ipa_utils.ssh_config(self.ssh_user, self.ssh_private_key)\ | ||
as ssh_config: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
inject_packages: /home/user/test.noarch.rpm | ||
inject_archives: /home/user/test.tar.xz | ||
install: python3 | ||
inject_files: /home/user/test.py | ||
execute: python test.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... installed on the test instance.