Skip to content

Commit

Permalink
Kelvin: added .gitignore file for acceptancetests - mostly for py stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed Apr 27, 2018
1 parent 280d8e4 commit 765e9dd
Show file tree
Hide file tree
Showing 27 changed files with 173 additions and 116 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ stage/
*.sw[nop]
.idea/
*.pyc
.vscode/
2 changes: 2 additions & 0 deletions acceptancetests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv/
*.deb
48 changes: 34 additions & 14 deletions acceptancetests/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
p=test*.py
py3="assess_model_change_watcher.py"
test:
TMPDIR=/tmp python -m unittest discover -vv . -p "$(p)"
mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
p = test*.py
py3 = assess_model_change_watcher.py
python_base_path = $(shell which python3)

.PHONY: test
test: ensure-venv
TMPDIR=/tmp python3 -m unittest discover -vv . -p "$(p)"
TMPDIR=/tmp python3 -m unittest discover -vv jujupy -t . -p "$(p)"
lint:
python3 -m flake8 --builtins xrange,basestring $(py3) --exclude=repository
flake8 --builtins xrange,basestring --exclude=$(py3),repository
cover:

.PHONY: lint
lint: ensure-venv
python3 -m flake8 --builtins xrange,basestring $(py3) --exclude=repository,venv
flake8 --builtins xrange,basestring --exclude=$(py3),repository,venv

.PHONY: cover
cover: ensure-venv
python -m coverage run --source="./" --omit "./tests/*" -m unittest discover -vv ./tests
python -m coverage report

.PHONY: clean
clean:
find . -name '*.pyc' -delete

.PHONY: apt-update
apt-update:
sudo apt-get -qq update

juju-ci-tools.common_0.1.4-0_all.deb: apt-update
find . -name '*.deb' -delete
sudo apt-get install -y equivs
equivs-build juju-ci-tools-common

.PHONY: install-deps
install-deps: juju-ci-tools.common_0.1.4-0_all.deb apt-update
sudo dpkg -i juju-ci-tools.common_0.1.4-0_all.deb || true
sudo apt-get install -y -f
pip install --user -r $(mkfile_dir)/requirements.txt
name=NAMEHERE
assess_file=assess_$(name).py
new-assess:
pip3 install -r $(mkfile_dir)requirements-dev.txt

name = NAMEHERE
assess_file = assess_$(name).py

.PHONY: new-assess
new-assess: ensure-venv
install -m 755 template_assess.py.tmpl $(assess_file)
sed -i -e "s/TEMPLATE/$(name)/g" $(assess_file) $(test_assess_file)
.PHONY: lint test cover clean new-assess apt-update install-deps

.PHONY: ensure-venv
ensure-venv:
test -d venv || virtualenv -p $(python_base_path) $(mkfile_dir)venv
. $(mkfile_dir)venv/bin/activate
8 changes: 4 additions & 4 deletions acceptancetests/assess_add_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from deploy_stack import (
BootstrapManager,
)
)
from utility import (
configure_logging,
add_basic_testing_arguments,
JujuAssertionError,
temp_dir,
)
)

__metaclass__ = type

Expand Down Expand Up @@ -76,7 +76,7 @@ def verify_add_credentials(args, env, cred):
'maas': add_maas,
'joyent': add_joyent,
'azure': add_azure
}
}

log.info("Adding {} credential from /cloud-city/credentials.yaml "
"into testing instance".format(args.env))
Expand Down Expand Up @@ -137,7 +137,7 @@ def end_session(session):
log.error('Buffer: {}'.format(session.buffer))
log.error('Before: {}'.format(session.before))
raise Exception('pexpect process exited with {}'.format(
session.exitstatus))
session.exitstatus))


def add_aws(child, env, cred):
Expand Down
6 changes: 3 additions & 3 deletions acceptancetests/assess_heterogeneous_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
client_from_config,
fake_juju_client,
JujuData,
)
)
from deploy_stack import (
BootstrapManager,
check_token,
get_random_string,
)
)
from jujuci import add_credential_args
from utility import (
configure_logging,
Expand Down Expand Up @@ -207,7 +207,7 @@ def wait_until_removed(client, agent_id):
raise AssertionError('Machine not destroyed: {}.'.format(agent_id))


def check_series(client, machine='0', series=None):
def check_series(client, machine='0', series=None):
"""Use 'juju ssh' to check that the deployed series meets expectations."""
result = client.get_juju_output('ssh', machine, 'lsb_release', '-c')
label, codename = result.rstrip().split('\t')
Expand Down
10 changes: 5 additions & 5 deletions acceptancetests/assess_model_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from distutils.version import (
LooseVersion,
StrictVersion
)
)
import logging
import os
from subprocess import CalledProcessError
Expand All @@ -20,7 +20,7 @@
from deploy_stack import (
BootstrapManager,
get_random_string
)
)
from jujupy.client import (
get_stripped_version_number,
)
Expand All @@ -32,7 +32,7 @@
assert_deployed_charm_is_responding,
deploy_dummy_source_to_new_model,
deploy_simple_server_to_new_model,
)
)
from remote import remote_from_address
from utility import (
JujuAssertionError,
Expand All @@ -41,7 +41,7 @@
qualified_model_name,
temp_dir,
until_timeout,
)
)


__metaclass__ = type
Expand Down Expand Up @@ -92,7 +92,7 @@ def assess_user_permission_model_migrations(source_client, dest_client):
def assess_development_branch_migrations(source_client, dest_client):
with temp_dir() as temp:
ensure_superuser_can_migrate_other_user_models(
source_client, dest_client, temp)
source_client, dest_client, temp)
ensure_migration_rolls_back_on_failure(source_client, dest_client)
ensure_api_login_redirects(source_client, dest_client)

Expand Down
10 changes: 5 additions & 5 deletions acceptancetests/assess_multimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
dump_env_logs,
get_random_string,
safe_print_status,
)
)
from jujupy import (
client_from_config,
)
)
from utility import (
add_basic_testing_arguments,
ensure_dir,
print_now,
)
)


def assess_multimodel_deploy(client, charm_series, log_dir, base_env):
Expand Down Expand Up @@ -78,7 +78,7 @@ def multimodel_setup(args):
args.logs, args.keep_env,
upload_tools=False,
region=args.region,
):
):
yield client, charm_series, base_env


Expand Down Expand Up @@ -107,7 +107,7 @@ def hosted_environment(system_client, log_dir, suffix):

def check_services(client):
token = env_token(client.env.environment)
client.set_config('dummy-source', {'token': token})
client.set_config('dummy-source', {'token': token})
print_now("checking services in " + client.env.environment)
check_token(client, token)

Expand Down
26 changes: 13 additions & 13 deletions acceptancetests/assess_network_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

from jujupy import (
client_for_existing
)
)
from jujupy.wait_condition import (
WaitApplicationNotPresent
)
)
from deploy_stack import (
BootstrapManager
)
)
from utility import (
add_basic_testing_arguments,
generate_default_clean_dir,
configure_logging,
wait_for_port
)
)
from substrate import (
maas_account_from_boot_config,
)
)

__metaclass__ = type

Expand All @@ -49,7 +49,7 @@ def __init__(self, args):
self.log_dir = args.logs
else:
self.log_dir = generate_default_clean_dir(
args.temp_env_name)
args.temp_env_name)
self.expose_client = None
self.existing_series = set([])
self.expose_test_charms = set([])
Expand Down Expand Up @@ -428,12 +428,12 @@ def parse_final_results(self, visibility, internet, exposed):
log.info('Parsing final results.')
error_string = []
for nh_source, service_result in visibility.items():
for service, unit_res in service_result.items():
if False in unit_res.values():
failed = [u for u, r in unit_res.items() if r is False]
error = ('Unit {0} failed to contact '
'targets(s): {1}'.format(nh_source, failed))
error_string.append(error)
for service, unit_res in service_result.items():
if False in unit_res.values():
failed = [u for u, r in unit_res.items() if r is False]
error = ('Unit {0} failed to contact '
'targets(s): {1}'.format(nh_source, failed))
error_string.append(error)
for unit, res in internet.items():
if not res:
error = 'Machine {} failed internet connection.'.format(unit)
Expand All @@ -451,7 +451,7 @@ def reboot_machines(self, client):
cont_ids = []
try:
cont_ids.extend([c['instance-id'] for c in
m_info.get('containers').values()])
m_info.get('containers').values()])
except KeyError:
log.info('No containers for machine: {}'.format(machine))
if cont_ids:
Expand Down
Loading

0 comments on commit 765e9dd

Please sign in to comment.