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 ability to use dev version of base package for e2e #2689

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import os

import click
import pyperclip

Expand All @@ -10,7 +12,7 @@
from ...e2e import derive_interface, start_environment, stop_environment
from ...test import get_available_tox_envs
from ...utils import get_tox_file
from ....utils import file_exists
from ....utils import dir_exists, file_exists, path_join


@click.command(
Expand All @@ -28,12 +30,26 @@
)
)
@click.option('--dev/--prod', help='Whether to use the latest version of a check or what is shipped')
@click.option('--base', is_flag=True, help='Whether to use the latest version of the base check or what is shipped')
@click.pass_context
def start(ctx, check, env, agent, dev):
def start(ctx, check, env, agent, dev, base):
"""Start an environment."""
if not file_exists(get_tox_file(check)):
abort('`{}` is not a testable check.'.format(check))

base_package = None
if base:
core_dir = os.path.expanduser(ctx.obj.get('core', ''))
if not dir_exists(core_dir):
if core_dir:
abort('`{}` directory does not exist.'.format(core_dir))
else:
abort('`core` config setting does not exist.')

base_package = path_join(core_dir, 'datadog_checks_base')
if not dir_exists(base_package):
abort('`datadog_checks_base` directory does not exist.')

envs = get_available_tox_envs(check, e2e_only=True)

if env not in envs:
Expand Down Expand Up @@ -73,7 +89,7 @@ def start(ctx, check, env, agent, dev):
stop_environment(check, env)
abort()

environment = interface(check, env, config, metadata, agent_build, api_key)
environment = interface(check, env, base_package, config, metadata, agent_build, api_key)

echo_waiting('Updating `{}`... '.format(agent_build), nl=False)
environment.update_agent()
Expand All @@ -99,11 +115,22 @@ def start(ctx, check, env, agent, dev):
abort()
echo_success('success!')

if base and not dev:
dev = True
echo_info(
'Will install the development version of the check too so the base package can import it (in editable mode)'
)

if dev:
echo_waiting('Upgrading `{}` check to the development version... '.format(check), nl=False)
environment.update_check()
echo_success('success!')

if base:
echo_waiting('Upgrading the base package to the development version... ', nl=False)
environment.update_base_package()
echo_success('success!')

click.echo()

try:
Expand Down
24 changes: 21 additions & 3 deletions datadog_checks_dev/datadog_checks/dev/tooling/e2e/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@


class DockerInterface(object):
def __init__(self, check, env, config=None, metadata=None, agent_build=None, api_key=None):
def __init__(self, check, env, base_package=None, config=None, metadata=None, agent_build=None, api_key=None):
self.check = check
self.env = env
self.base_package = base_package
self.config = config or {}
self.metadata = metadata or {}
self.agent_build = agent_build
Expand All @@ -37,6 +38,10 @@ def agent_version(self):
def check_mount_dir(self):
return '/home/{}'.format(self.check)

@property
def base_mount_dir(self):
return '/home/datadog_checks_base'

@property
def agent_command(self):
return 'docker exec {} {}'.format(
Expand Down Expand Up @@ -80,6 +85,12 @@ def update_check(self):
]
run_command(command, capture=True, check=True)

def update_base_package(self):
command = [
'docker', 'exec', self.container_name, 'pip', 'install', '-e', self.base_mount_dir
]
run_command(command, capture=True, check=True)

def update_agent(self):
if self.agent_build:
run_command(['docker', 'pull', self.agent_build], capture=True, check=True)
Expand All @@ -101,9 +112,16 @@ def start_agent(self):
'-v', '{}:{}'.format(self.config_dir, get_agent_conf_dir(self.check, self.agent_version)),
# Mount the check directory
'-v', '{}:{}'.format(path_join(get_root(), self.check), self.check_mount_dir),
# The chosen tag
self.agent_build
]

if self.base_package:
# Mount the check directory
command.append('-v')
command.append('{}:{}'.format(self.base_package, self.base_mount_dir))

# The chosen tag
command.append(self.agent_build)

return run_command(command, capture=True)

def stop_agent(self):
Expand Down