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

Add upgrade lxd profile tests #9776

Merged
merged 2 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 8 additions & 21 deletions acceptancetests/assess_deploy_lxd_profile_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
add_basic_testing_arguments,
configure_logging,
JujuAssertionError,
is_subordinate,
subordinate_machines,
application_machines,
align_machine_profiles,
)
from jujupy.wait_condition import (
AgentsIdle,
WaitForLXDProfilesConditions,
)

Expand Down Expand Up @@ -61,31 +64,15 @@ def assess_profile_machines(client):
if 'charm-profile' in info:
charm_profile = info['charm-profile']
if charm_profile:
machines = application_machines(info)
if is_subordinate(info):
machines = subordinate_machines(info, apps)
else:
machines = application_machines(info)
machine_profiles.append((charm_profile, machines))
if len(machine_profiles) > 0:
aligned_machine_profiles = align_machine_profiles(machine_profiles)
client.wait_for(WaitForLXDProfilesConditions(aligned_machine_profiles))

def application_machines(app_data):
"""Get all the machines used to host the given application."""
machines = [unit_data['machine'] for unit_data in
app_data['units'].values()]
return machines

def align_machine_profiles(machine_profiles):
result = {}
for items in machine_profiles:
charm_profile = items[0]
if charm_profile in result:
# drop duplicates using set difference
a = set(result[charm_profile])
b = set(items[1])
result[charm_profile].extend(b.difference(a))
else:
result[charm_profile] = list(items[1])
return result

def parse_args(argv):
parser = argparse.ArgumentParser(description="Test juju lxd profile bundle deploys.")
parser.add_argument(
Expand Down
92 changes: 92 additions & 0 deletions acceptancetests/assess_upgrade_lxd_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python

""" Assess upgrading charms with lxd-profiles in different deployment scenarios.
"""

import argparse
import logging
import os
import sys

from deploy_stack import (
BootstrapManager,
)
from jujucharm import (
local_charm_path,
)
from utility import (
add_basic_testing_arguments,
configure_logging,
JujuAssertionError,
is_subordinate,
subordinate_machines,
application_machines,
align_machine_profiles,
)
from jujupy.wait_condition import (
WaitForLXDProfilesConditions,
)

__metaclass__ = type

log = logging.getLogger("assess_lxdprofile_charm")

default_bundle = 'bundles-lxd-profile-upgrade.yaml'

def deploy_bundle(client):
"""Deploy the given charm bundle
:param client: Jujupy ModelClient object
"""
bundle = local_charm_path(
charm=default_bundle,
juju_ver=client.version,
repository=os.environ['JUJU_REPOSITORY']
)
_, primary = client.deploy(bundle)
client.wait_for(primary)

def upgrade_charm(client):
client.upgrade_charm("lxd-profile", resvision='1')

def assess_profile_machines(client):
"""Assess the machines
"""
# Ensure we wait for everything to start before checking the profiles,
# that way we can ensure that things have been installed.
client.wait_for_started()

machine_profiles = []
status = client.get_status()
apps = status.get_applications()
for _, info in apps.items():
if 'charm-profile' in info:
charm_profile = info['charm-profile']
if charm_profile:
if is_subordinate(info):
machines = subordinate_machines(info, apps)
else:
machines = application_machines(info)
machine_profiles.append((charm_profile, machines))
if len(machine_profiles) > 0:
aligned_machine_profiles = align_machine_profiles(machine_profiles)
client.wait_for(WaitForLXDProfilesConditions(aligned_machine_profiles))

def parse_args(argv):
parser = argparse.ArgumentParser(description="Test juju lxd profile bundle deploys.")
add_basic_testing_arguments(parser)
return parser.parse_args(argv)

def main(argv=None):
args = parse_args(argv)
configure_logging(args.verbose)
bs_manager = BootstrapManager.from_args(args)
with bs_manager.booted_context(args.upload_tools):
client = bs_manager.client

deploy_bundle(client)
assess_profile_machines(client)
upgrade_charm(client)
assess_profile_machines(client)

if __name__ == '__main__':
sys.exit(main())
4 changes: 3 additions & 1 deletion acceptancetests/jujupy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,10 +1270,12 @@ def wait_for_resource(self, resource_id, service_or_unit, timeout=60):
'ResourceId: {} Service or Unit: {} Timeout: {}'.format(
resource_id, service_or_unit, timeout))

def upgrade_charm(self, service, charm_path=None):
def upgrade_charm(self, service, charm_path=None, resvision=None):
args = (service,)
if charm_path is not None:
args = args + ('--path', charm_path)
if resvision is not None:
args = args + ('--revision', resvision)
self.juju('upgrade-charm', args)

def remove_service(self, service):
Expand Down
22 changes: 22 additions & 0 deletions acceptancetests/repository/bundles-lxd-profile-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
series: bionic
applications:
lxd-profile:
charm: cs:~juju-qa/bionic/lxd-profile-without-devices-0
num_units: 2
to:
- "0"
- "1"
lxd-profile-subordinate:
charm: cs:~juju-qa/bionic/lxd-profile-subordinate-1
ubuntu:
charm: cs:~jameinel/ubuntu-lite
num_units: 2
to:
- "0"
- "1"
machines:
"0": {}
SimonRichardson marked this conversation as resolved.
Show resolved Hide resolved
"1": {}
relations:
- - lxd-profile:juju-info
- lxd-profile-subordinate:juju-info
30 changes: 30 additions & 0 deletions acceptancetests/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,33 @@ def list_models(client):
log.error('Failed to list current models due to error: {}'.format(e))
raise e
return json.loads(raw)

def is_subordinate(app_data):
return (not 'unit' in app_data) and ('subordinate-to' in app_data)

def application_machines(app_data):
SimonRichardson marked this conversation as resolved.
Show resolved Hide resolved
"""Get all the machines used to host the given application."""
machines = [unit_data['machine'] for unit_data in
app_data['units'].values()]
return machines

def subordinate_machines(app_data, apps):
machines = []
SimonRichardson marked this conversation as resolved.
Show resolved Hide resolved
for sub_name in app_data['subordinate-to']:
for app_name, prim_app_data in apps.items():
if sub_name == app_name:
machines.extend(application_machines(prim_app_data))
return machines

def align_machine_profiles(machine_profiles):
SimonRichardson marked this conversation as resolved.
Show resolved Hide resolved
result = {}
for items in machine_profiles:
charm_profile = items[0]
if charm_profile in result:
# drop duplicates using set difference
a = set(result[charm_profile])
b = set(items[1])
result[charm_profile].extend(b.difference(a))
else:
result[charm_profile] = list(items[1])
return result