Git Product home page Git Product logo

img-proof's Introduction

Continuous testing & Linting Documentation Status Py Versions License

img-proof

overview

img-proof (IPA) provides a command line utility to test images in the Public Cloud (AWS, Azure, GCE, etc.).

With img-proof you can now test custom images in a cloud framework agnostic way with one tool and one API. In the first release, img-proof supports the openSUSE and SLES distributions. It also supports the three largest cloud frameworks (AWS, Azure and GCE). However, it is intended to be distribution agnostic and framework transparent so both are easily extensible.

For each distribution there are specific synchronization points that must be provided. These currently include soft reboot and system update. The synch points not only test functionality but also act as dividers to separate distinct sections of a test suite. For example you can run a test to ensure the proper repos exist before and after a system update. The system update synch point will guarantee the order of tests. Speaking of tests, if you're already familiar with Pytest conventions there's no need to learn a whole new unit testing framework. img-proof is written in Python and leverages the Pytest framework through Testinfra.

Installation

To install the package use the following commands as root:

$ zypper ar http://download.opensuse.org/repositories/Cloud:/Tools/<distribution>
$ zypper refresh
$ zypper in python3-img-proof

Requirements

  • boto3
  • apache-libcloud
  • azure-common
  • azure-mgmt-compute
  • azure-mgmt-network
  • azure-mgmt-resource
  • Click
  • paramiko
  • pytest
  • PyYaml
  • testinfra
  • oci

Tests

img-proof uses the Testinfra package for writing unit tests. Testinfra leverages Pytest and provides modules such as Package, Process and Service to test the state of images. See the Testinfra Docs for more information on writing infrastructure tests.

img-proof currently passes the Pytest option -x (stop on first failure) through as --early-exit. If there's an interest or need for any other options/args please submit an issue to Github.

CLI Overview

The CLI provides multiple subcommands to initiate image testing:

  • img-proof test

    Test image in the given framework using the supplied test files.

  • img-proof results

    Invokes the default show subcommand img-proof results show 1.

  • img-proof results clear

    Clear the results from the history file.

  • img-proof results delete

    Delete the specified history item from the history log.

  • img-proof results list`

    Display list of results history.

  • img-proof results show

    Display the results or log file for a history item.

  • img-proof list

    Print a list of test files or test cases.

Issues/Enhancements

Please submit issues and requests to Github.

Contributing

Contributions to ipa are welcome and encouraged. See CONTRIBUTING for info on getting started.

License

Copyright (c) 2018 SUSE LLC.

Distributed under the terms of GPL-3.0+ license, see LICENSE for details.

img-proof's People

Contributors

apozsuse avatar asmorodskyi avatar bear454 avatar cfconrad avatar conan-kudo avatar grisu48 avatar jgleissner avatar jlausuch avatar ricardobranco777 avatar rjschwei avatar smarlowucf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

img-proof's Issues

Add Config setup endpoint

It would be a nice enhancement to have a config setup option in CLI. This would help the user setup the ipa config and/or all config files with info for testing. Since a user may not have config setup for ec2utils, azurectl or Google.

ipa setup

Series of prompts requesting config data.

EC2 instance might not be visible after launch

It's possible that a newly launched instance is not queryable via DescribeInstances right after launch. This will cause an unhandled exception in the _get_instance_state method that causes img-proof to crash without cleaning up properly.

ERROR 2019-12-10 19:40:03,634 TestingService
    Pass[1]: Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/img_proof/ipa_ec2.py", line 210, in _get_instance_state
    state = instance.state['Name']
  File "/usr/lib/python3.6/site-packages/boto3/resources/factory.py", line 339, in property_loader
    self.load()
  File "/usr/lib/python3.6/site-packages/boto3/resources/factory.py", line 505, in do_action
    response = action(self, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/usr/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidInstanceID.NotFound) when calling the DescribeInstances operation: The instance ID 'i-00c7aeb7ca53015f3' does not exist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/mash/services/testing/ec2_job.py", line 139, in run_job
    tests=self.tests
  File "/usr/lib/python3.6/site-packages/mash/services/testing/img_proof_helper.py", line 51, in img_proof_test
    timeout=img_proof_timeout
  File "/usr/lib/python3.6/site-packages/img_proof/ipa_controller.py", line 132, in test_image
    return cloud.test_image()
  File "/usr/lib/python3.6/site-packages/img_proof/ipa_cloud.py", line 669, in test_image
    self._launch_instance()
  File "/usr/lib/python3.6/site-packages/img_proof/ipa_ec2.py", line 273, in _launch_instance
    self._wait_on_instance('running', self.timeout)
  File "/usr/lib/python3.6/site-packages/img_proof/ipa_cloud.py", line 474, in _wait_on_instance
    current_state = self._get_instance_state()
  File "/usr/lib/python3.6/site-packages/img_proof/ipa_ec2.py", line 215, in _get_instance_state
    instance_id=self.running_instance_id
img_proof.ipa_exceptions.EC2CloudException: Instance with id: i-00c7aeb7ca53015f3, cannot be found.

This is hard to confirm given the error seems to be very infrequent. However, adding a slight delay before getting the instance state should resolve this. To prevent an instance being left in running state the exception should be handled gracefully which will allow img-proof to log the failure and do proper cleanup.

Allow reading of results from an archive

If ipa handles listing results from an archive then the user should just give us the archive name, i.e.

ipa results list --archive $PATH_TO_MY_ARCHIVE
ipa results show 5 --archive $PATH_TO_MY_ARCHIVE

And ipa should just extract the file on the fly to get the results.

Question is should this be to a temp dir which is deleted after the command or should it be cached somehow for subsequent calls?

Test config files

Consider implementing some sort of test config files to simplify running tests multiple times and running similar tests.

This file would contain default command line args/options minimizing the length of command line statements.

Could be helpful if a user has many tests that use a similar set of options/args.

ipa needs a new name to prevent confusion with existing packages

This is document the steps for the package rename which are as follows:

  • Rename project in GitHub
  • Setup project in Travis for CI
  • Create a new read the docs project and hook to build docs
  • Add new project to PyPI
  • Deprecate / remove old python3-ipa project from PyPI
  • Release a new version of python3-img-proof in OBS
  • Propagate package to all projects in OBS
  • Any usages of ipa config will need migrated to ~/.config/img_proof/config to prevent confusion from using ~/.config/ipa/config.
  • Any usages of ipa will need to confirm the ~/img_proof directory is created.
  • Any usages of the config file will need to change the ipa section to img_proof.

Failed test before sync point prevents results aggregation

If a test fails prior to a sync point any subsequent tests are skipped and results are not aggregated to summary.

Scenario:
ipa test ... test_something_fails test_update test_another_thing

ipa results
>> FAILED tests=1|pass=0|fail=1|error=0

The second test is ignored.

Add SSH provider

There are cases where it would be helpful to run IPA tests against an instance via SSH without the requirement of provider credentials.

  • The SSH backend would require a new instance-ip argument.
  • All methods that require API authentication will do nothing (pass).
  • A new flag will be required --ssh-only and provider will still be a required argument.

ipa test ... --instance-ip 10.0.0.1 --ssh-only ec2

If the repos test can pull CSP name from metadata it could be updated and this would then just be a new provider name. #112

ipa test ... --instance-ip 10.0.0.1 ssh

Sync point tests do not log on failure

If there is an error in a sync tests such as update the error is not logged. The exception is thrown and caught by CLI.

Problems:

  • Error not logged
  • Results file is not written
  • Log file is not updated

Instead the error should be caught and logged and event loop should fail gracefully.

SLES tests infer CSP and region

For the SLES tests we can infer the cloud environment from dmidecode.

e.g. (google, amazon, microsoft) in output.lower():

sudo dmidecode -t system

With this we can find the region from meta-data. This way the parameters don't need injected and tests can be run on an instance without the need of provider based class.

SSH private key option name confusing

The --ssh-private-key option is confusing. Consider renaming it to --ssh-private-key-file.

I think the best route is to add a new arg --ssh-private-key-file and deprecate the old one. Or we can add another option name then remove the old one in a subsequent version.

@click.option(
    '--ssh-private-key',
    '--ssh-private-key-file',
    type=click.Path(exists=True),
    help='SSH private key file for accessing instance.'
)

Timeouts Not Sufficient

Problem: The timeouts for SSH connections and instance state changes are not always sufficient.

This depends on things like provider, network, region and instance size.

Make these timeouts configurable through (a) command line option(s).

repo test

The suse specific repository test should provide more details. With the switch to the modules and the various flavors of repositories, source, debuginfo etc. it has pretty much become impossible to manually verify registration success. IPA provides the necessary functionality. However, the registration test has a pass/fail status leaving the user/verifyer with the original problem. the test shold produce a diff list in the results if the repo data does not match the expected content. This should hopefully allow the person verifying the test results an opportunity to understand the failure and address it.

Exception with SSH connection leaves instance running

If there is an exception with the initial SSH connection after an instance is launched the instance is not cleaned up and the results are not properly logged.

Ensure that any exception during testing is handled properly. With the exception handling cleanup the instance if necessary and log results.

IPA Should run without config file

Instead of throwing an error when config file is not found attempt to run tests with provided command line args.

Config file not found: /{user-home}/.config/ipa/config

Cannot test against EC2 without config file

Currently an image cannot be tested in EC2 without the .ecutils.conf config file. Even if all values have been provided via command line.

Allow for testing images in EC2 without a configuration file so long as all required args have been supplied via command line.

Also if the config file is optional then the account_name should also be optional.

Verbose test list creates error

~> ipa list -v
ERROR: file not found: /home/ec2-user/ipa/tests/

expected behavior is to ignore the non-extant directory and list the available tests

Apache libcloud

Consider migrating EC2 and Azure to Apache Libcloud to minimize dependencies and make providers more uniform.

This would also make adding new providers much easier so long as they are supported by libcloud.

Todo:

  • GCE
  • EC2
  • Azure

Error when testing with new results file

If ipa test is invoked with --history-log and the path does not exist yet an error is raised.

Error: Invalid value for "-h" / "--history-log": Path "foobar" does not exist.

Instead ipa should attempt to create path for new file.

Verbose results fails with sync test

With sync tests now in results if results are printed with verbose flag there is an error.

The sync tests have no path and should just be returned when parsing.

Invalid distro using API fails too late

If an IPA test is started using the API instead of the CLI the distro name is not validated until after an instance is launched.

The set_distro method should instead be called prior to launching or connecting to the instance. This ensures the distro name is validated eagerly.

Move report plugin

The results report plugin provides a simple dict output of pytest results. This is used for merging multiple results in a single ipa test run. For a more thorough report move to the pytest json plugin. This will require a patch submitted upstream and an option to make report accessible from code instead of saved to a json file.

traceback generated during mash run

ERROR 2019-05-20 20:14:03,773 TestingService
Pass[1]: Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/ipa/ipa_cloud.py", line 636, in test_im
age
client
File "/usr/lib/python3.6/site-packages/ipa/ipa_utils.py", line 262, in get_hos
t_key_fingerprint
client.get_transport().get_remote_server_key().get_fingerprint()
File "/usr/lib/python3.6/site-packages/paramiko/transport.py", line 761, in ge
t_remote_server_key
raise SSHException("No existing session")
paramiko.ssh_exception.SSHException: No existing session

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/mash/services/testing/ipa_helper.py", l
ine 95, in ipa_test
timeout=ipa_timeout
File "/usr/lib/python3.6/site-packages/ipa/ipa_controller.py", line 131, in te
st_image
return cloud.test_image()
File "/usr/lib/python3.6/site-packages/ipa/ipa_cloud.py", line 644, in test_im
age
'An error occurred retrieving host key: %s' % error
ipa.ipa_exceptions.IpaCloudException: An error occurred retrieving host key: No
existing session

mash job id: 4f8c81dd-cfd4-4697-be5f-1777c6c4b220

IPA Terminates a running instance

When a running instance is provided with the -r option the instance is terminated if tests pass. This can be configured using the --cleanup/--no-cleanup however the instance by default should be left running.

Using -r should always leave the instance running.
Using -i should terminate the instance if all tests pass.
And --cleanup/--no-cleanup override the default functionality.

Archive management

ipa needs to be able to archive results and the history file. For example

ipa results --create-archive --location my_network_drive/ipa_results/my_distro_version_tests --results 1,2,3,6,7,9,10

where the numbers correspond to the index of the results list from

ipa results --list

Paramiko flaky timeout errors

There continues to be random flaky paramiko errors during pytest runs. Should investigate a solution where we can re-run tests if they get ssh exceptions. Either retry via pytest mechanism or run all tests separately so img-proof can handle retries.

Registration command should use systemctl

When the test_sles_wait_on_registration.py test was written there was an issue that required using pgrep to get service status. This should be re-tested to pinpoint the issue or cleanup the test.

Region and running instance id overlap

This appears to be a bug in Click:

If the region shorthand is used without the running instance id the region value is put on running_instance_id.

ipa test ... -r us-west-1 -i ami-123456 ...

Instance with ID: us-west-1 not found.

Whereas this works fine:

ipa test ... -r us-west-1 -R i-1234567890 ...

Test update is not needed for on demand

For on demand test suite the update is not necessary. If refresh passes then things are good. Add a new sync test for refresh and use that instead of test_update in test_sles_on_demand.

Account for SKIPPED tests

If a test is skipped it is not accounted for by ipa results.

Number of skipped should be part of output:

PASSED tests=1|pass=0|fail=0|error=0

And the verbose styled output should be yellow or green not red.

test_sles_force_new_smt_reg::test_sles_force_new_smt_reg SKIPPED

License path is incorrect for Leap 15.1

__________________ test_leap_license[paramiko://13.93.160.99] __________________

host = <testinfra.host.Host object at 0x7f34e1475e48>

    def test_leap_license(host):
        license_dir = '/etc/YaST2/licenses/base'
        license_content = 'LICENSE AGREEMENT'
    
        lic_dir = host.file(license_dir)
>       assert lic_dir.exists
E       assert False
E        +  where False = <file /etc/YaST2/licenses/base>.exists

usr/share/lib/ipa/tests/openSUSE_Leap/test_leap_license.py:6: AssertionError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.