Merge lp:~canonical-platform-qa/snappy-ecosystem-tests/allow-environment-variable-export into lp:snappy-ecosystem-tests

Proposed by Omer Akram
Status: Merged
Approved by: Santiago Baldassin
Approved revision: 31
Merged at revision: 30
Proposed branch: lp:~canonical-platform-qa/snappy-ecosystem-tests/allow-environment-variable-export
Merge into: lp:snappy-ecosystem-tests
Diff against target: 61 lines (+14/-5)
1 file modified
snappy_ecosystem_tests/environment/managers.py (+14/-5)
To merge this branch: bzr merge lp:~canonical-platform-qa/snappy-ecosystem-tests/allow-environment-variable-export
Reviewer Review Type Date Requested Status
Santiago Baldassin (community) Approve
platform-qa-bot continuous-integration Approve
Review via email: mp+318927@code.launchpad.net

Commit message

Allow export of environment variables inside container.

Description of the change

Allow export of environment variables inside container.

To post a comment you must log in.
31. By Omer Akram

simple

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'snappy_ecosystem_tests/environment/managers.py'
--- snappy_ecosystem_tests/environment/managers.py 2017-03-03 13:44:31 +0000
+++ snappy_ecosystem_tests/environment/managers.py 2017-03-03 15:53:20 +0000
@@ -34,6 +34,10 @@
34from snappy_ecosystem_tests.environment.data.snapd import (34from snappy_ecosystem_tests.environment.data.snapd import (
35 DEFAULT_CONTAINER_CONFIG, SNAPD_CONTAINER_NAME)35 DEFAULT_CONTAINER_CONFIG, SNAPD_CONTAINER_NAME)
3636
37COMMAND_ALLOW_ENV_VARS = 'sed -i \'/^AcceptEnv/ s/$/ {}/\' ' \
38 '/etc/ssh/sshd_config'
39
40
37def get_manager(mode):41def get_manager(mode):
38 """Get the manager for the given mode"""42 """Get the manager for the given mode"""
39 supported_modules = {43 supported_modules = {
@@ -88,7 +92,6 @@
88 container_name,92 container_name,
89 DEPENDENCIES[container_type] + DEPENDENCIES['shared'])93 DEPENDENCIES[container_type] + DEPENDENCIES['shared'])
9094
91
92 def configure(self, container_name, container_type, profile):95 def configure(self, container_name, container_type, profile):
93 """Configure a given container"""96 """Configure a given container"""
94 container = self.client.containers.get(container_name)97 container = self.client.containers.get(container_name)
@@ -102,13 +105,20 @@
102 @retry(stop_max_attempt_number=5, wait_fixed=3000,105 @retry(stop_max_attempt_number=5, wait_fixed=3000,
103 retry_on_exception=lambda exception: isinstance(106 retry_on_exception=lambda exception: isinstance(
104 exception, LXDAPIException))107 exception, LXDAPIException))
105 def enable_ssh(self, container_name):108 def enable_ssh(self, container_name, container_type, profile):
106 """Enable the ssh connection on the container"""109 """Enable the ssh connection on the container"""
107 container = self.client.containers.get(container_name)110 container = self.client.containers.get(container_name)
108 pub_key = open(111 pub_key = open(
109 os.path.expanduser('~') + '/.ssh/id_rsa.pub').read().strip('\n')112 os.path.expanduser('~') + '/.ssh/id_rsa.pub').read().strip('\n')
110 container.files.put('/home/ubuntu/.ssh/authorized_keys', pub_key)113 container.files.put('/home/ubuntu/.ssh/authorized_keys', pub_key)
111114 # Allow export of environment variables over ssh.
115 container.execute(
116 COMMAND_ALLOW_ENV_VARS.format(
117 ' '.join(PROFILES[profile][container_type]
118 ['environment_variables'].keys())
119 )
120 )
121 container.execute('service ssh restart')
112122
113 def setup(self, profile):123 def setup(self, profile):
114 """setup the container based on the profile"""124 """setup the container based on the profile"""
@@ -116,14 +126,13 @@
116 self._setup(126 self._setup(
117 SNAPCRAFT_CONTAINER_NAME, constants.SNAPCRAFT, profile)127 SNAPCRAFT_CONTAINER_NAME, constants.SNAPCRAFT, profile)
118128
119
120 def _setup(self, container_name, container_type, profile):129 def _setup(self, container_name, container_type, profile):
121 """130 """
122 Launch a container, enable ssh, install dependencies131 Launch a container, enable ssh, install dependencies
123 and setup the needed environment variables132 and setup the needed environment variables
124 """133 """
125 self.launch(container_name)134 self.launch(container_name)
126 self.enable_ssh(container_name)135 self.enable_ssh(container_name, container_type, profile)
127 self.install(136 self.install(
128 container_name,137 container_name,
129 packages=[PROFILES[profile][container_type]["package_name"]],138 packages=[PROFILES[profile][container_type]["package_name"]],

Subscribers

People subscribed via source and target branches