Merge lp:~canonical-platform-qa/snappy-ecosystem-tests/export-staging-variables-ssh into lp:snappy-ecosystem-tests

Proposed by Omer Akram
Status: Merged
Approved by: I Ahmad
Approved revision: 31
Merged at revision: 28
Proposed branch: lp:~canonical-platform-qa/snappy-ecosystem-tests/export-staging-variables-ssh
Merge into: lp:snappy-ecosystem-tests
Prerequisite: lp:~canonical-platform-qa/snappy-ecosystem-tests/register-snap-tests
Diff against target: 72 lines (+23/-7)
2 files modified
snappy_ecosystem_tests/environment/data/snapd.py (+12/-3)
snappy_ecosystem_tests/utils/ssh.py (+11/-4)
To merge this branch: bzr merge lp:~canonical-platform-qa/snappy-ecosystem-tests/export-staging-variables-ssh
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Approve
Heber Parrucci (community) Abstain
Review via email: mp+318743@code.launchpad.net

This proposal supersedes a proposal from 2017-03-02.

Commit message

Export staging variables over ssh.

Description of the change

Ensure staging environment variables are available over ssh.

To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Omer Akram (om26er) wrote : Posted in a previous version of this proposal

By default ssh is secure and does not allow any random environment variable to be exported. So the ssh config within the container also needs to be updated to allow these variables to be exported.

That can be enabled by container setup script. We basically need to append staging environment variable names to AcceptEnv key inside /etc/ssh/sshd_config. OR if we just want to put this variables inside /etc/environment while we setup the container, that would work, though I am not a fan of that.

For testing just update the AcceptEnv line in the container to

AcceptEnv *

Revision history for this message
Omer Akram (om26er) wrote : Posted in a previous version of this proposal

(and restart the container)

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
26. By Omer Akram

Finish rebase

27. By Omer Akram

fix

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Heber Parrucci (heber013) wrote :

Comment inline

review: Needs Fixing
28. By Omer Akram

fix per suggestion

Revision history for this message
Omer Akram (om26er) wrote :

replied inline.

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
29. By Omer Akram

merge with pre-req

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
30. By Omer Akram

ignore arguments-differ pylint warning

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Heber Parrucci (heber013) wrote :

Comments inline. Thanks

review: Needs Fixing
Revision history for this message
I Ahmad (iahmad) wrote :

+1 for heber's recommendation, env should not be hard coded rather
configurable based on value in config file

On Fri, Mar 3, 2017 at 2:29 AM, Heber Parrucci <<email address hidden>
> wrote:

> Review: Needs Fixing
>
> Comments inline. Thanks
>
> Diff comments:
>
> >
> > === modified file 'snappy_ecosystem_tests/utils/ssh.py'
> > --- snappy_ecosystem_tests/utils/ssh.py 2017-03-02 20:39:08 +0000
> > +++ snappy_ecosystem_tests/utils/ssh.py 2017-03-02 20:39:08 +0000
> > @@ -31,13 +33,13 @@
> > class SSHClient(paramiko.SSHClient):
> > """Extended SSHClient."""
> >
> > - def exec_command(self, command, bufsize=-1, timeout=None,
> get_pty=False,
> > - cwd=''):
> > + def exec_command(self, command, bufsize=-1, timeout=None,
> get_pty=False, # pylint: disable=arguments-differ
>
> If we disable the rules every time pylint warns us about something, we are
> losing the tool benefits and would be the same as not using it at all.
> In this particular case you are changing the parent method signature which
> could be ok in some cases. But if we look deeper in the problem, you have
> created an SSHClient and overrided exec_command just to change the dir when
> executing the command. I think this is not necessary at all... You could
> use the paramiko function and achieve the same. And the trick will be in
> the helper side... For example in case of snapd:
> http://paste.ubuntu.com/24098212/
>
> > + environment=None, cwd=''):
> > """Execute the given command over ssh."""
> > if cwd:
> > command = 'cd {}; {}'.format(cwd, command)
> > _, stdout, stderr = super().exec_command(command, bufsize,
> timeout,
> > - get_pty)
> > + get_pty, environment)
> > if stdout.channel.recv_exit_status() != 0:
> > raise ValueError(stderr.read().decode().strip())
> > response = stdout.read().decode().strip()
> > @@ -118,4 +120,9 @@
> > _hostname, _username, _port = get_snapd_remote_host_credentials()
> > ssh = SSHManager.get_instance(
> > hostname or _hostname, username or _username, port or _port)
> > - return ssh.exec_command(command, cwd=cwd)
> > + return ssh.exec_command(
> > + command,
> > + cwd=cwd,
> > + environment=STAGING_VARIABLES if get_current_store() ==
> 'staging'
>
> It is almost the same than before the fix. What I meant when wrote the
> suggestion is to dynamically pass the corresponding environment variables
> depending on the current store. You could have a function that returns the
> corresponding dictionary containing the variables and receives the store
> name as parameter. So in the future if we need to add variables for example
> for production, we just create the dictionary and that's all, we don't need
> to change this method for that.
>
> > + else None
> > + )
>
>
> --
> https://code.launchpad.net/~canonical-platform-qa/snappy-
> ecosystem-tests/export-staging-variables-ssh/+merge/318743
> You are subscribed to branch lp:snappy-ecosystem-tests.
>

Revision history for this message
Omer Akram (om26er) wrote :

replied inline.

Revision history for this message
I Ahmad (iahmad) wrote :

There could be situation where container is previously set to staging but
now needs to be reset to the production (in cases where environment needs
to be reused).

On Fri, Mar 3, 2017 at 4:48 PM, Omer Akram <email address hidden> wrote:

> replied inline.
>
> Diff comments:
>
> >
> > === modified file 'snappy_ecosystem_tests/utils/ssh.py'
> > --- snappy_ecosystem_tests/utils/ssh.py 2017-03-02 20:39:08 +0000
> > +++ snappy_ecosystem_tests/utils/ssh.py 2017-03-02 20:39:08 +0000
> > @@ -31,13 +33,13 @@
> > class SSHClient(paramiko.SSHClient):
> > """Extended SSHClient."""
> >
> > - def exec_command(self, command, bufsize=-1, timeout=None,
> get_pty=False,
> > - cwd=''):
> > + def exec_command(self, command, bufsize=-1, timeout=None,
> get_pty=False, # pylint: disable=arguments-differ
>
> pylint is picky, yes. But since I am trying to extend the functionality of
> a method, I added a new parameter, quite normal.
>
> pylint threw that warning because it could easily be a mistake on my end,
> but given its intentional, I had to silence pylint for that. The reason I
> added that override was inspired by the conversation I found on pylint'
> mailing list[1].
>
> [1] http://code.activestate.com/lists/python-list/188090/
>
> > + environment=None, cwd=''):
> > """Execute the given command over ssh."""
> > if cwd:
> > command = 'cd {}; {}'.format(cwd, command)
> > _, stdout, stderr = super().exec_command(command, bufsize,
> timeout,
> > - get_pty)
> > + get_pty, environment)
> > if stdout.channel.recv_exit_status() != 0:
> > raise ValueError(stderr.read().decode().strip())
> > response = stdout.read().decode().strip()
> > @@ -118,4 +120,9 @@
> > _hostname, _username, _port = get_snapd_remote_host_credentials()
> > ssh = SSHManager.get_instance(
> > hostname or _hostname, username or _username, port or _port)
> > - return ssh.exec_command(command, cwd=cwd)
> > + return ssh.exec_command(
> > + command,
> > + cwd=cwd,
> > + environment=STAGING_VARIABLES if get_current_store() ==
> 'staging'
>
> I might be a little off here but if we don't export any variables we are
> by default on production. Only staging parameters need to be exported, if
> that's not the case, can you please show a code example so that I can
> incorporate that in.
>
> > + else None
> > + )
>
>
> --
> https://code.launchpad.net/~canonical-platform-qa/snappy-
> ecosystem-tests/export-staging-variables-ssh/+merge/318743
> You are subscribed to branch lp:snappy-ecosystem-tests.
>

Revision history for this message
Heber Parrucci (heber013) wrote :

Reply inline

review: Needs Fixing
Revision history for this message
Omer Akram (om26er) wrote :

Heber, replied inline.

Revision history for this message
Omer Akram (om26er) wrote :

> There could be situation where container is previously set to staging but
> now needs to be reset to the production (in cases where environment needs
> to be reused).

if get_current_store() returns staging, then staging variables will be available, if it returns 'production' then by default production variables will be exported.

>
> On Fri, Mar 3, 2017 at 4:48 PM, Omer Akram <email address hidden> wrote:
>
> > replied inline.
> >
> > Diff comments:
> >
> > >
> > > === modified file 'snappy_ecosystem_tests/utils/ssh.py'
> > > --- snappy_ecosystem_tests/utils/ssh.py 2017-03-02 20:39:08 +0000
> > > +++ snappy_ecosystem_tests/utils/ssh.py 2017-03-02 20:39:08 +0000
> > > @@ -31,13 +33,13 @@
> > > class SSHClient(paramiko.SSHClient):
> > > """Extended SSHClient."""
> > >
> > > - def exec_command(self, command, bufsize=-1, timeout=None,
> > get_pty=False,
> > > - cwd=''):
> > > + def exec_command(self, command, bufsize=-1, timeout=None,
> > get_pty=False, # pylint: disable=arguments-differ
> >
> > pylint is picky, yes. But since I am trying to extend the functionality of
> > a method, I added a new parameter, quite normal.
> >
> > pylint threw that warning because it could easily be a mistake on my end,
> > but given its intentional, I had to silence pylint for that. The reason I
> > added that override was inspired by the conversation I found on pylint'
> > mailing list[1].
> >
> > [1] http://code.activestate.com/lists/python-list/188090/
> >
> > > + environment=None, cwd=''):
> > > """Execute the given command over ssh."""
> > > if cwd:
> > > command = 'cd {}; {}'.format(cwd, command)
> > > _, stdout, stderr = super().exec_command(command, bufsize,
> > timeout,
> > > - get_pty)
> > > + get_pty, environment)
> > > if stdout.channel.recv_exit_status() != 0:
> > > raise ValueError(stderr.read().decode().strip())
> > > response = stdout.read().decode().strip()
> > > @@ -118,4 +120,9 @@
> > > _hostname, _username, _port = get_snapd_remote_host_credentials()
> > > ssh = SSHManager.get_instance(
> > > hostname or _hostname, username or _username, port or _port)
> > > - return ssh.exec_command(command, cwd=cwd)
> > > + return ssh.exec_command(
> > > + command,
> > > + cwd=cwd,
> > > + environment=STAGING_VARIABLES if get_current_store() ==
> > 'staging'
> >
> > I might be a little off here but if we don't export any variables we are
> > by default on production. Only staging parameters need to be exported, if
> > that's not the case, can you please show a code example so that I can
> > incorporate that in.
> >
> > > + else None
> > > + )
> >
> >
> > --
> > https://code.launchpad.net/~canonical-platform-qa/snappy-
> > ecosystem-tests/export-staging-variables-ssh/+merge/318743
> > You are subscribed to branch lp:snappy-ecosystem-tests.
> >

31. By Omer Akram

merge with trunk

Revision history for this message
Heber Parrucci (heber013) wrote :

reply inline

review: Abstain
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Heber Parrucci (heber013) wrote :

Reply inline

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snappy_ecosystem_tests/environment/data/snapd.py'
2--- snappy_ecosystem_tests/environment/data/snapd.py 2017-03-01 10:28:47 +0000
3+++ snappy_ecosystem_tests/environment/data/snapd.py 2017-03-03 13:01:15 +0000
4@@ -67,15 +67,24 @@
5 {'command': COMMAND_APT_INSTALL_STAGING_DEBS, 'cwd': DIRECTORY_CLONE}
6 ]
7
8-CONTAINER_ENV_VARS = {
9- 'GOPATH': CONTAINER_HOME,
10- 'SNAPPY_USE_STAGING_STORE': '1',
11+SNAPCRAFT_STAGING_VARIABLES = {
12 ENV_STORE_API_ROOT: URL_API_ROOT,
13 ENV_STORE_SEARCH_ROOT: URL_SEARCH_ROOT,
14 ENV_STORE_UPLOAD_ROOT: URL_UPLOAD_ROOT,
15 ENV_SSO_API_ROOT: URL_SSO_API_ROOT,
16 }
17
18+SNAPD_STAGING_VARIABLES = {
19+ 'SNAPPY_USE_STAGING_STORE': '1'
20+}
21+
22+STAGING_VARIABLES = dict(
23+ SNAPCRAFT_STAGING_VARIABLES, **SNAPD_STAGING_VARIABLES)
24+
25+CONTAINER_ENV_VARS = {
26+ 'GOPATH': CONTAINER_HOME,
27+}
28+
29 DEFAULT_CONTAINER_CONFIG = {
30 "name": "snapd",
31 "source": {
32
33=== modified file 'snappy_ecosystem_tests/utils/ssh.py'
34--- snappy_ecosystem_tests/utils/ssh.py 2017-03-02 18:36:24 +0000
35+++ snappy_ecosystem_tests/utils/ssh.py 2017-03-03 13:01:15 +0000
36@@ -24,6 +24,8 @@
37 import paramiko
38
39 from snappy_ecosystem_tests.utils.user import get_snapd_remote_host_credentials
40+from snappy_ecosystem_tests.utils.storeconfig import get_current_store
41+from snappy_ecosystem_tests.environment.data.snapd import STAGING_VARIABLES
42
43 LOGGER = logging.getLogger(__name__)
44
45@@ -31,13 +33,13 @@
46 class SSHClient(paramiko.SSHClient):
47 """Extended SSHClient."""
48
49- def exec_command(self, command, bufsize=-1, timeout=None, get_pty=False,
50- cwd=''):
51+ def exec_command(self, command, bufsize=-1, timeout=None, get_pty=False, # pylint: disable=arguments-differ
52+ environment=None, cwd=''):
53 """Execute the given command over ssh."""
54 if cwd:
55 command = 'cd {}; {}'.format(cwd, command)
56 _, stdout, stderr = super().exec_command(command, bufsize, timeout,
57- get_pty)
58+ get_pty, environment)
59 if stdout.channel.recv_exit_status() != 0:
60 raise ValueError(stderr.read().decode().strip())
61 response = stdout.read().decode().strip()
62@@ -118,4 +120,9 @@
63 _hostname, _username, _port = get_snapd_remote_host_credentials()
64 ssh = SSHManager.get_instance(
65 hostname or _hostname, username or _username, port or _port)
66- return ssh.exec_command(command, cwd=cwd)
67+ return ssh.exec_command(
68+ command,
69+ cwd=cwd,
70+ environment=STAGING_VARIABLES if get_current_store() == 'staging'
71+ else None
72+ )

Subscribers

People subscribed via source and target branches