Merge ~nacc/git-ubuntu:lp1741949-unset-snap-in-lxc-env into git-ubuntu:master

Proposed by Nish Aravamudan
Status: Merged
Approved by: Robie Basak
Approved revision: 467d0f591f7fcd79b7fb7a99ca6be12585ffc3ef
Merged at revision: 699b0185f4ed61eceb754e95568de12417ad3ad5
Proposed branch: ~nacc/git-ubuntu:lp1741949-unset-snap-in-lxc-env
Merge into: git-ubuntu:master
Diff against target: 217 lines (+75/-46)
2 files modified
gitubuntu/build.py (+36/-46)
gitubuntu/run.py (+39/-0)
Reviewer Review Type Date Requested Status
Robie Basak Approve
Andreas Hasenack Approve
Server Team CI bot continuous-integration Approve
Nish Aravamudan Pending
Review via email: mp+336391@code.launchpad.net

This proposal supersedes a proposal from 2018-01-18.

Commit message

Make Jenkins happy.

Description of the change

Make Jenkins happy.

To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote : Posted in a previous version of this proposal

Why are we unsetting SNAP for some calls to lxc, but not all of them? Is there some criteria we have to use to decide this? Or are you just working around the calls that happen to break for now?

As long as we have to work around some other project's bug, I'd like to have a bug reference in a comment in our code which shows us why the workaround is present and what its status is for us to get rid of it. So when I asked for a bug against this, I meant I wanted an open bug task against the project which we are working around (whether that is snapd or lxd I'm not sure).

review: Needs Information
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:c21e653eddde8b9ad7d4d89ee56ede9a4d504dc1
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~racb/usd-importer/+git/usd-importer/+merge/336297/+edit-commit-message

https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/246/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/246/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:d16589b9f2835f9cf1cae6daf228447b343e7330
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~racb/usd-importer/+git/usd-importer/+merge/336297/+edit-commit-message

https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/250/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/250/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:3e1087eb7c21e31b2f07bf3c44591102914ab0f1
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    FAILED: Integration Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Nish Aravamudan (nacc) wrote :

There is a typo in my last run.py line, I'll try and fix it to pass CI this
weekend.

On Jan 19, 2018 17:52, "Server Team CI bot" <
<email address hidden>> wrote:

> Review: Needs Fixing continuous-integration
>
> FAILED: Continuous integration, rev:3e1087eb7c21e31b2f07bf3c445911
> 02914ab0f1
> https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/
> Executed test runs:
> SUCCESS: Checkout
> SUCCESS: Style Check
> SUCCESS: Unit Tests
> FAILED: Integration Tests
>
> Click here to trigger a rebuild:
> https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/254/rebuild
>
> --
> https://code.launchpad.net/~nacc/usd-importer/+git/usd-
> importer/+merge/336391
> You are the owner of ~nacc/usd-importer:lp1741949-unset-snap-in-lxc-env.
>

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:467d0f591f7fcd79b7fb7a99ca6be12585ffc3ef
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/255/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/255/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Nice to see it applied to all lxc commands, and even nicer to see a green CI run :)

+1

review: Approve
Revision history for this message
Robie Basak (racb) wrote :

Thanks! I'll merge this now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/gitubuntu/build.py b/gitubuntu/build.py
index 072d3e7..22b95a9 100644
--- a/gitubuntu/build.py
+++ b/gitubuntu/build.py
@@ -35,7 +35,13 @@ from gitubuntu.cache import CACHE_PATH
35from gitubuntu.dsc import GitUbuntuDsc35from gitubuntu.dsc import GitUbuntuDsc
36import gitubuntu.lint36import gitubuntu.lint
37import gitubuntu.git_repository37import gitubuntu.git_repository
38from gitubuntu.run import decode_binary, run, runq38from gitubuntu.run import (
39 decode_binary,
40 get_cmd_in_origpath,
41 run,
42 runq,
43 run_lxc,
44)
39from gitubuntu.source_information import (45from gitubuntu.source_information import (
40 GitUbuntuSourceInformation,46 GitUbuntuSourceInformation,
41 NoPublicationHistoryException,47 NoPublicationHistoryException,
@@ -889,15 +895,6 @@ def do_build_host_exitstack(
889895
890 return built_pardir_contents896 return built_pardir_contents
891897
892def get_cmd_in_origpath(cmd):
893 return shutil.which(
894 cmd,
895 path=os.getenv(
896 'ORIG_PATH',
897 os.getenv('PATH', os.defpath),
898 ),
899 )
900
901@functools.lru_cache()898@functools.lru_cache()
902def _gpg_abspath():899def _gpg_abspath():
903 orig_gpg = get_cmd_in_origpath('gpg')900 orig_gpg = get_cmd_in_origpath('gpg')
@@ -905,18 +902,11 @@ def _gpg_abspath():
905 return orig_gpg902 return orig_gpg
906 raise RuntimeError("Unable to find a gpg binary, is it installed?")903 raise RuntimeError("Unable to find a gpg binary, is it installed?")
907904
908@functools.lru_cache()
909def _lxc_abspath():
910 orig_lxc = get_cmd_in_origpath('lxc')
911 if orig_lxc:
912 return orig_lxc
913 raise RuntimeError("Unable to find a lxc binary, is it installed?")
914
915def _cleanup_lxd(container_name):905def _cleanup_lxd(container_name):
916 run([_lxc_abspath(), 'stop', '--force', container_name])906 run_lxc(['stop', '--force', container_name])
917907
918def _run_in_lxd(container_name, args, user=None, **kwargs):908def _run_in_lxd(container_name, args, user=None, **kwargs):
919 cmd = [_lxc_abspath(), 'exec', container_name, '--',]909 _args = ['exec', container_name, '--',]
920 # user == None means run as root910 # user == None means run as root
921 if user:911 if user:
922 try:912 try:
@@ -944,9 +934,9 @@ def _run_in_lxd(container_name, args, user=None, **kwargs):
944 )934 )
945 else:935 else:
946 raise936 raise
947 cmd.extend(['sudo', '-s', '-H', '-u', user,])937 _args.extend(['sudo', '-s', '-H', '-u', user,])
948 cmd.extend(args)938 _args.extend(args)
949 return run(cmd, **kwargs)939 return run_lxc(_args, **kwargs)
950940
951def do_build_lxd_exitstack(941def do_build_lxd_exitstack(
952 changelog,942 changelog,
@@ -960,19 +950,18 @@ def do_build_lxd_exitstack(
960 retry_backoffs,950 retry_backoffs,
961 stack,951 stack,
962):952):
963 lxc = _lxc_abspath()
964 try:953 try:
965 run([lxc, 'list'])954 run_lxc(['list'])
966 except Exception as e:955 except Exception as e:
967 raise RuntimeError("LXD running?") from e956 raise RuntimeError("LXD running?") from e
968957
969 container_name = petname.Generate(2, '-')958 container_name = petname.Generate(2, '-')
970959
971 cmd = [lxc, 'launch', '-e']960 args = ['launch', '-e']
972 if profile:961 if profile:
973 cmd.extend(['-p', profile])962 args.extend(['-p', profile])
974 if image:963 if image:
975 cmd.extend([image,])964 args.extend([image,])
976 else:965 else:
977 try:966 try:
978 source = derive_source_from_changelog(changelog)967 source = derive_source_from_changelog(changelog)
@@ -985,12 +974,12 @@ def do_build_lxd_exitstack(
985 raise974 raise
986 if source == 'ubuntu':975 if source == 'ubuntu':
987 # devel is properly handled for the daily remote976 # devel is properly handled for the daily remote
988 cmd.extend(['ubuntu-daily:%s' % series,])977 args.extend(['ubuntu-daily:%s' % series,])
989 else:978 else:
990 cmd.extend(['images:debian/%s' % series,])979 args.extend(['images:debian/%s' % series,])
991 cmd.extend([container_name,])980 args.extend([container_name,])
992 try:981 try:
993 run(cmd)982 run_lxc(args)
994 except Exception as e:983 except Exception as e:
995 raise RuntimeError("Failed to launch ephemeral build container") from e984 raise RuntimeError("Failed to launch ephemeral build container") from e
996985
@@ -1030,23 +1019,24 @@ def do_build_lxd_exitstack(
1030 )1019 )
10311020
1032 try:1021 try:
1033 run([1022 run_lxc(
1034 lxc,1023 [
1035 'file',1024 'file',
1036 'push',1025 'push',
1037 archive_tarball_name,1026 archive_tarball_name,
1038 '%s/tmp/' % container_name,1027 '%s/tmp/' % container_name,
1039 ])1028 ],
1029 )
1040 except Exception as e:1030 except Exception as e:
1041 raise RuntimeError(1031 raise RuntimeError(
1042 "Failed to push archive tarball to ephemeral build container"1032 "Failed to push archive tarball to ephemeral build container"
1043 ) from e1033 ) from e
10441034
1045 cmd = [lxc, 'file', 'push']1035 args = ['file', 'push']
1046 cmd.extend(tarballs)1036 args.extend(tarballs)
1047 cmd.extend(['%s/tmp/' % container_name,])1037 args.extend(['%s/tmp/' % container_name,])
1048 try:1038 try:
1049 run(cmd)1039 run_lxc(args)
1050 except Exception as e:1040 except Exception as e:
1051 raise RuntimeError("Failed to push orig tarballs to container") from e1041 raise RuntimeError("Failed to push orig tarballs to container") from e
10521042
@@ -1142,14 +1132,14 @@ def do_build_lxd_exitstack(
1142 )1132 )
11431133
1144 built_temp_contents = new_temp_contents - orig_temp_contents1134 built_temp_contents = new_temp_contents - orig_temp_contents
1145 cmd = [lxc, 'file', 'pull']1135 args = ['file', 'pull']
1146 cmd.extend([1136 args.extend([
1147 '%s%s' % (container_name, os.path.join('/tmp', f))1137 '%s%s' % (container_name, os.path.join('/tmp', f))
1148 for f in built_temp_contents1138 for f in built_temp_contents
1149 ]1139 ]
1150 )1140 )
1151 cmd.extend([os.pardir,])1141 args.extend([os.pardir,])
1152 run(cmd)1142 run_lxc(args)
11531143
1154 return [os.path.join(os.pardir, f) for f in built_temp_contents]1144 return [os.path.join(os.pardir, f) for f in built_temp_contents]
11551145
diff --git a/gitubuntu/run.py b/gitubuntu/run.py
index 4b1a86c..8fb4d85 100644
--- a/gitubuntu/run.py
+++ b/gitubuntu/run.py
@@ -1,4 +1,7 @@
1import functools
1import logging2import logging
3import os
4import shutil
2import subprocess5import subprocess
36
47
@@ -102,3 +105,39 @@ def decode_binary(binary, verbose=True):
102 logging.warning("Failed to decode blob: %s", e)105 logging.warning("Failed to decode blob: %s", e)
103 logging.warning("blob=%s", binary.decode(errors='replace'))106 logging.warning("blob=%s", binary.decode(errors='replace'))
104 return binary.decode('utf-8', errors='replace')107 return binary.decode('utf-8', errors='replace')
108
109def get_cmd_in_origpath(cmd):
110 return shutil.which(
111 cmd,
112 path=os.getenv(
113 'ORIG_PATH',
114 os.getenv('PATH', os.defpath),
115 ),
116 )
117
118@functools.lru_cache()
119def _lxc_abspath():
120 orig_lxc = get_cmd_in_origpath('lxc')
121 if orig_lxc:
122 return orig_lxc
123 raise RuntimeError("Unable to find a lxc binary, is it installed?")
124
125
126def run_lxc(args, env=None, **kwargs):
127 cmd = [_lxc_abspath()] + args
128 # lxd assumes that if SNAP is set in the environment, that it is
129 # running as a snap. That is not necessarily true when git-ubuntu is
130 # the snapped application. So unset SNAP before we exec.
131 # LP: #1741949
132 # This can be dropped if https://github.com/lxc/lxd/issues/4183 is
133 # resolved.
134 if env:
135 env_unset_SNAP = env.copy()
136 else:
137 env_unset_SNAP = os.environ.copy()
138 try:
139 del env_unset_SNAP['SNAP']
140 except KeyError:
141 pass
142
143 return run(cmd, env=env_unset_SNAP, **kwargs)

Subscribers

People subscribed via source and target branches