Skip to content

Commit

Permalink
Merge pull request #60 from SUSE/provider-case
Browse files Browse the repository at this point in the history
Remove magic in ipa controller.
  • Loading branch information
rjschwei authored Jan 31, 2018
2 parents 2f8dc93 + 6df669d commit b752df1
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 62 deletions.
4 changes: 2 additions & 2 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ that is cloud framework independent such as the test dir and results dir.
tests=~/ipa/tests/
results=~/ipa/results/
[EC2]
[ec2]
region=us-west-1
----

Expand All @@ -84,7 +84,7 @@ GCE uses service accounts for authentication. See
link:https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances[GCE docs]
for more info on creating a service account json file. The file must include
a key pair for proper authentication. Additional configuration options can
be placed in the `GCE` section of the `ipa` configuration file.
be placed in the `gce` section of the `ipa` configuration file.

== Tests

Expand Down
2 changes: 1 addition & 1 deletion docs/source.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public cloud environment. The image id, tests and provider are required
arguments. See below for options:

----
Example: ipa test --ssh-private-key /path/to/key -d SLES Azure test_image
Example: ipa test --ssh-private-key /path/to/key -d SLES azure test_image
----

ipa results
Expand Down
12 changes: 6 additions & 6 deletions docs/start.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ To override the default configuration location the CLI option `-C` or `--config`
is provided.

The following is an example configuration file. The ipa section is required
and the provider sections are optional and can be [EC2], [GCE] or [Azure].
and the provider sections are optional and can be [ec2], [gce] or [azure].

[source,ini]
----
[ipa]
tests=~/ipa/tests/
results=~/ipa/results/
[EC2]
[ec2]
region=us-west-1
----

Expand All @@ -80,7 +80,7 @@ GCE uses service accounts for authentication. See
link:https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances[GCE docs]
for more info on creating a service account json file. The file must include
a key pair for proper authentication. Additional configuration options can
be placed in the `GCE` section of the `ipa` configuration file.
be placed in the `gce` section of the `ipa` configuration file.

=== Provider Configuration location

Expand All @@ -104,7 +104,7 @@ Test image in the given framework using the supplied test files.
--provider-config ~/.ec2utils.conf \
--no-cleanup \
-d openSUSE_Leap \
EC2 test_image
ec2 test_image
Starting instance
Running tests /home/{user}/ipa/tests/test_image.py
Expand All @@ -119,7 +119,7 @@ PASSED tests=1|pass=1|fail=0|error=0
--no-cleanup \
-d openSUSE_Leap \
--ssh-private-key {azure-ssh-key-file} \
Azure test_image
azure test_image
Starting instance
Running tests /home/{user}/ipa/tests/test_image.py
Expand All @@ -133,7 +133,7 @@ PASSED tests=1|pass=1|fail=0|error=0
> ipa test -i {image-id} \
--no-cleanup \
-d openSUSE_Leap \
GCE test_image
gce test_image
Starting instance
Running tests /home/{user}/ipa/tests/test_image.py
Expand Down
2 changes: 1 addition & 1 deletion ipa/ipa_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self,
test_dirs=None,
test_files=None):
"""Initialize Azure Provider class."""
super(AzureProvider, self).__init__('Azure',
super(AzureProvider, self).__init__('azure',
cleanup,
config,
desc,
Expand Down
2 changes: 1 addition & 1 deletion ipa/ipa_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
HOME = os.path.expanduser('~')
NOT_IMPLEMENTED = 'Implement method in child classes.'
SUPPORTED_DISTROS = ('openSUSE_Leap', 'SLES')
SUPPORTED_PROVIDERS = ('Azure', 'EC2', 'GCE')
SUPPORTED_PROVIDERS = ('azure', 'ec2', 'gce')

AZURE_DEFAULT_TYPE = 'Small'
AZURE_DEFAULT_USER = 'azureuser'
Expand Down
73 changes: 38 additions & 35 deletions ipa/ipa_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import importlib
import json
import pytest
import shlex

from ipa.collect_items import CollectItemsPlugin
from ipa.ipa_constants import SUPPORTED_PROVIDERS, TEST_PATHS
from ipa.ipa_azure import AzureProvider
from ipa.ipa_constants import TEST_PATHS
from ipa.ipa_ec2 import EC2Provider
from ipa.ipa_exceptions import IpaControllerException
from ipa.ipa_gce import GCEProvider
from ipa.ipa_utils import get_test_files


Expand Down Expand Up @@ -58,44 +60,45 @@ def test_image(provider_name,
test_dirs=None,
tests=None):
"""Creates a cloud provider instance and initiates testing."""
if provider_name in SUPPORTED_PROVIDERS:
provider_module = importlib.import_module(
'ipa.ipa_%s' % provider_name.lower()
)
provider_class = '%sProvider' % provider_name

provider = getattr(provider_module, provider_class)(
access_key_id=access_key_id,
account_name=account,
cleanup=cleanup,
config=config,
desc=desc,
distro_name=distro,
early_exit=early_exit,
history_log=history_log,
image_id=image_id,
instance_type=instance_type,
log_level=log_level,
no_default_test_dirs=no_default_test_dirs,
provider_config=provider_config,
region=region,
results_dir=results_dir,
running_instance_id=running_instance_id,
secret_access_key=secret_access_key,
service_account_file=service_account_file,
ssh_key_name=ssh_key_name,
ssh_private_key=ssh_private_key,
ssh_user=ssh_user,
storage_container=storage_container,
subnet_id=subnet_id,
test_dirs=test_dirs,
test_files=tests
)
if provider_name == 'azure':
provider_class = AzureProvider
elif provider_name == 'ec2':
provider_class = EC2Provider
elif provider_name == 'gce':
provider_class = GCEProvider
else:
raise IpaControllerException(
'Provider: %s unavailable.' % provider_name
)

provider = provider_class(
access_key_id=access_key_id,
account_name=account,
cleanup=cleanup,
config=config,
desc=desc,
distro_name=distro,
early_exit=early_exit,
history_log=history_log,
image_id=image_id,
instance_type=instance_type,
log_level=log_level,
no_default_test_dirs=no_default_test_dirs,
provider_config=provider_config,
region=region,
results_dir=results_dir,
running_instance_id=running_instance_id,
secret_access_key=secret_access_key,
service_account_file=service_account_file,
ssh_key_name=ssh_key_name,
ssh_private_key=ssh_private_key,
ssh_user=ssh_user,
storage_container=storage_container,
subnet_id=subnet_id,
test_dirs=test_dirs,
test_files=tests
)

return provider.test_image()


Expand Down
2 changes: 1 addition & 1 deletion ipa/ipa_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self,
test_dirs=None,
test_files=None):
"""Initialize EC2 provider class."""
super(EC2Provider, self).__init__('EC2',
super(EC2Provider, self).__init__('ec2',
cleanup,
config,
desc,
Expand Down
2 changes: 1 addition & 1 deletion ipa/ipa_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self,
subnet_id=None,
test_dirs=None,
test_files=None):
super(GCEProvider, self).__init__('GCE',
super(GCEProvider, self).__init__('gce',
cleanup,
config,
desc,
Expand Down
4 changes: 2 additions & 2 deletions tests/data/config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[ipa]
test_dirs = tests/data/tests

[Azure]
[azure]
region = West US

[EC2]
[ec2]
region = us-west-1
4 changes: 2 additions & 2 deletions tests/data/config.noregion
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[ipa]
test_dirs = tests/data/tests

[Azure]
[azure]

[EC2]
[ec2]
2 changes: 1 addition & 1 deletion tests/data/history.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform: EC2
platform: ec2
distro: SLES
image: ami-859bd1e5
instance: i-44444444444444444
Expand Down
2 changes: 1 addition & 1 deletion tests/data/history.results
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info": {"platform": "EC2", "image": "ami-859bd1e5", "instance": "i-44444444444444444", "timestamp": "20170626142856", "distro": "SLES"}, "tests": [], "summary": {"duration": 0, "passed": 0, "num_tests": 0}}
{"info": {"platform": "ec2", "image": "ami-859bd1e5", "instance": "i-44444444444444444", "timestamp": "20170626142856", "distro": "SLES"}, "tests": [], "summary": {"duration": 0, "passed": 0, "num_tests": 0}}
2 changes: 1 addition & 1 deletion tests/data/test.results
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info": {"platform": "Azure", "image": "test_image", "instance": "azure-ipa-test", "timestamp": "20170622155322", "distro": "SLES"}, "tests": [{"name": "ipa/tests/test_sles.py::test_sles", "teardown": {"duration": 4.506111145019531e-05, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 9.989738464355469e-05, "outcome": "passed", "name": "setup"}, "run_index": 0, "call": {"duration": 6.604194641113281e-05, "outcome": "passed", "name": "call"}, "duration": 0.0003108978271484375, "outcome": "passed"}], "summary": {"duration": 0.0045049190521240234, "passed": 1, "num_tests": 1}}
{"info": {"platform": "azure", "image": "test_image", "instance": "azure-ipa-test", "timestamp": "20170622155322", "distro": "SLES"}, "tests": [{"name": "ipa/tests/test_sles.py::test_sles", "teardown": {"duration": 4.506111145019531e-05, "outcome": "passed", "name": "teardown"}, "setup": {"duration": 9.989738464355469e-05, "outcome": "passed", "name": "setup"}, "run_index": 0, "call": {"duration": 6.604194641113281e-05, "outcome": "passed", "name": "call"}, "duration": 0.0003108978271484375, "outcome": "passed"}], "summary": {"duration": 0.0045049190521240234, "passed": 1, "num_tests": 1}}
2 changes: 1 addition & 1 deletion tests/test_ipa_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_cli_test_image_exception():
runner = CliRunner()
result = runner.invoke(
main,
['test', 'EC2', '-d', 'SLES', '-C', 'tests/data/config']
['test', 'ec2', '-d', 'SLES', '-C', 'tests/data/config']
)
assert result.exit_code != 0
assert 'Image ID or running instance is required.' in result.output
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ipa_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

DATA = {
"info": {
"platform": "Azure",
"platform": "azure",
"image": "test_image",
"instance": "azure-ipa-test",
"timestamp": "20170622155322",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ipa_libcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from unittest.mock import MagicMock, patch

args = ['EC2']
args = ['ec2']


class TestLibcloudProvider(object):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ipa_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from unittest.mock import MagicMock, patch

args = ['EC2']
args = ['ec2']

NOT_IMPL_METHODS = [
'_get_instance',
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_provider_run_tests(self, mock_pytest, mock_merge_results):

provider.terminate = True
provider.results['info'] = {
'platform': 'EC2',
'platform': 'ec2',
'region': 'us-west-1'
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ipa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ def test_utils_get_from_config():
config = ipa_utils.get_config('tests/data/config')

with pytest.raises(IpaUtilsException) as error:
ipa_utils.get_from_config(config, 'EC2', 'ipa', 'fakevalue')
ipa_utils.get_from_config(config, 'ec2', 'ipa', 'fakevalue')

assert str(error.value) == 'Unable to get fakevalue value from config.'

val = ipa_utils.get_from_config(config, 'EC2', 'ipa', 'region')
val = ipa_utils.get_from_config(config, 'ec2', 'ipa', 'region')
assert val == 'us-west-1'


Expand Down

0 comments on commit b752df1

Please sign in to comment.