Merge lp:~zyga/checkbox/fix-1328903 into lp:checkbox

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: Daniel Manrique
Approved revision: 3066
Merged at revision: 3066
Proposed branch: lp:~zyga/checkbox/fix-1328903
Merge into: lp:checkbox
Diff against target: 147 lines (+48/-8)
4 files modified
plainbox/plainbox/impl/ctrl.py (+9/-7)
plainbox/plainbox/impl/test_ctrl.py (+14/-1)
plainbox/plainbox/impl/unit/job.py (+13/-0)
plainbox/plainbox/impl/unit/test_job.py (+12/-0)
To merge this branch: bzr merge lp:~zyga/checkbox/fix-1328903
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Review via email: mp+222835@code.launchpad.net

Description of the change

7547a44 plainbox:unit:job: add JobDefinition.flags
e298a86 plainbox:unit:job: add JobDefinition.get_flag_set()
3e24bd8 plainbox:ctrl: add support for 'preserve-locale' flag
c589d44 plainbox:ctrl: fix typo in a comment

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

We need to document the new flags: field, and document possible values since this is handled magically in the code; otherwise this risks becoming an arcane feature nobody will be able to use (like environ: which is rather obscure).

But code-wise, this is OK, so let's go ahead.

review: Approve
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Good point. I'll work on documenting this

On Wed, Jun 11, 2014 at 6:40 PM, Daniel Manrique <
<email address hidden>> wrote:

> The proposal to merge lp:~zkrynicki/checkbox/fix-1328903 into lp:checkbox
> has been updated.
>
> Status: Needs review => Approved
>
> For more details, see:
> https://code.launchpad.net/~zkrynicki/checkbox/fix-1328903/+merge/222835
> --
> https://code.launchpad.net/~zkrynicki/checkbox/fix-1328903/+merge/222835
> You are the owner of lp:~zkrynicki/checkbox/fix-1328903.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plainbox/plainbox/impl/ctrl.py'
2--- plainbox/plainbox/impl/ctrl.py 2014-06-10 12:51:38 +0000
3+++ plainbox/plainbox/impl/ctrl.py 2014-06-11 16:22:48 +0000
4@@ -512,13 +512,15 @@
5 """
6 # Get a proper environment
7 env = dict(os.environ)
8- # Use non-internationalized environment
9- env['LANG'] = 'C.UTF-8'
10- if 'LANGUAGE' in env:
11- del env['LANGUAGE']
12- for name in list(env.keys()):
13- if name.startswith("LC_"):
14- del env[name]
15+ # Neuter locale unless 'preserve-locale' flag is set
16+ if 'preserve-locale' not in job.get_flag_set():
17+ # Use non-internationalized environment
18+ env['LANG'] = 'C.UTF-8'
19+ if 'LANGUAGE' in env:
20+ del env['LANGUAGE']
21+ for name in list(env.keys()):
22+ if name.startswith("LC_"):
23+ del env[name]
24 # Use PATH that can lookup checkbox scripts
25 if job.provider.extra_PYTHONPATH:
26 env['PYTHONPATH'] = os.pathsep.join(
27
28=== modified file 'plainbox/plainbox/impl/test_ctrl.py'
29--- plainbox/plainbox/impl/test_ctrl.py 2014-06-10 12:51:38 +0000
30+++ plainbox/plainbox/impl/test_ctrl.py 2014-06-11 16:22:48 +0000
31@@ -533,6 +533,8 @@
32 extra_PYTHONPATH=None,
33 CHECKBOX_SHARE='CHECKBOX_SHARE',
34 data_dir='data_dir', units_dir='units_dir'))
35+ # Mock the default flags (empty set)
36+ self.job.get_flag_set.return_value = frozenset()
37 # Create mocked config.
38 # Put an empty dictionary of environment overrides
39 # that is expected by get_execution_environment()
40@@ -655,9 +657,18 @@
41 # Call the tested method
42 env = self.ctrl.get_execution_environment(
43 self.job, self.config, self.NEST_DIR)
44- # Ensure that LANG is rese to C.UTF-8
45+ # Ensure that LANG is reset to C.UTF-8
46 self.assertEqual(env['LANG'], 'C.UTF-8')
47
48+ @mock.patch.dict('os.environ', clear=True, LANG='fake_LANG')
49+ def test_get_execution_environment_preserves_LANG_if_requested(self):
50+ self.job.get_flag_set.return_value = {'preserve-locale'}
51+ # Call the tested method
52+ env = self.ctrl.get_execution_environment(
53+ self.job, self.config, self.NEST_DIR)
54+ # Ensure that LANG is what we mocked it to be
55+ self.assertEqual(env['LANG'], 'fake_LANG')
56+
57 @mock.patch.dict('os.environ', clear=True, PYTHONPATH='PYTHONPATH')
58 def test_get_execution_environment_keeps_PYTHONPATH(self):
59 # Call the tested method
60@@ -756,6 +767,8 @@
61 data_dir="data_dir-generator",
62 units_dir="units_dir-generator",
63 CHECKBOX_SHARE='CHECKBOX_SHARE-generator'))
64+ # Mock the default flags (empty set)
65+ self.job.origin.source.job.get_flag_set.return_value = frozenset()
66 PATH = os.pathsep.join([self.NEST_DIR, 'vanilla-path'])
67 expected = [
68 'pkexec', '--user', self.job.user,
69
70=== modified file 'plainbox/plainbox/impl/unit/job.py'
71--- plainbox/plainbox/impl/unit/job.py 2014-05-23 13:44:32 +0000
72+++ plainbox/plainbox/impl/unit/job.py 2014-06-11 16:22:48 +0000
73@@ -309,6 +309,10 @@
74 return self.get_record_value('user')
75
76 @property
77+ def flags(self):
78+ return self.get_record_value('flags')
79+
80+ @property
81 def shell(self):
82 """
83 Shell that is used to interpret the command
84@@ -368,6 +372,15 @@
85 else:
86 return set()
87
88+ def get_flag_set(self):
89+ """
90+ Return a set of flags associated with this job
91+ """
92+ if self.flags is not None:
93+ return {flag for flag in re.split('[\s,]+', self.flags)}
94+ else:
95+ return set()
96+
97 @property
98 def automated(self):
99 """
100
101=== modified file 'plainbox/plainbox/impl/unit/test_job.py'
102--- plainbox/plainbox/impl/unit/test_job.py 2014-05-23 13:44:32 +0000
103+++ plainbox/plainbox/impl/unit/test_job.py 2014-06-11 16:22:48 +0000
104@@ -67,18 +67,21 @@
105 'environ': 'environ-value',
106 'user': 'user-value',
107 'shell': 'shell-value',
108+ 'flags': 'flags-value',
109 }, raw_data={
110 'plugin': 'plugin-raw',
111 'command': 'command-raw',
112 'environ': 'environ-raw',
113 'user': 'user-raw',
114 'shell': 'shell-raw',
115+ 'flags': 'flags-raw',
116 })
117 self.assertEqual(job.plugin, "plugin-value")
118 self.assertEqual(job.command, "command-value")
119 self.assertEqual(job.environ, "environ-value")
120 self.assertEqual(job.user, "user-value")
121 self.assertEqual(job.shell, "shell-value")
122+ self.assertEqual(job.flags, "flags-value")
123
124 def test_properties_default_values(self):
125 """
126@@ -90,6 +93,7 @@
127 self.assertEqual(job.environ, None)
128 self.assertEqual(job.user, None)
129 self.assertEqual(job.shell, 'bash')
130+ self.assertEqual(job.flags, None)
131
132 def test_checksum_smoke(self):
133 job1 = JobDefinition({'plugin': 'plugin', 'user': 'root'})
134@@ -112,6 +116,14 @@
135 job3 = JobDefinition({'environ': 'a,b,c'})
136 self.assertEqual(job3.get_environ_settings(), set(['a', 'b', 'c']))
137
138+ def test_get_flag_set(self):
139+ job1 = JobDefinition({})
140+ self.assertEqual(job1.get_flag_set(), set())
141+ job2 = JobDefinition({'flags': 'a b c'})
142+ self.assertEqual(job2.get_flag_set(), set(['a', 'b', 'c']))
143+ job3 = JobDefinition({'flags': 'a,b,c'})
144+ self.assertEqual(job3.get_flag_set(), set(['a', 'b', 'c']))
145+
146
147 class JobDefinitionParsingTests(TestCaseWithParameters):
148

Subscribers

People subscribed via source and target branches