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
=== modified file 'plainbox/plainbox/impl/ctrl.py'
--- plainbox/plainbox/impl/ctrl.py 2014-06-10 12:51:38 +0000
+++ plainbox/plainbox/impl/ctrl.py 2014-06-11 16:22:48 +0000
@@ -512,13 +512,15 @@
512 """512 """
513 # Get a proper environment513 # Get a proper environment
514 env = dict(os.environ)514 env = dict(os.environ)
515 # Use non-internationalized environment515 # Neuter locale unless 'preserve-locale' flag is set
516 env['LANG'] = 'C.UTF-8'516 if 'preserve-locale' not in job.get_flag_set():
517 if 'LANGUAGE' in env:517 # Use non-internationalized environment
518 del env['LANGUAGE']518 env['LANG'] = 'C.UTF-8'
519 for name in list(env.keys()):519 if 'LANGUAGE' in env:
520 if name.startswith("LC_"):520 del env['LANGUAGE']
521 del env[name]521 for name in list(env.keys()):
522 if name.startswith("LC_"):
523 del env[name]
522 # Use PATH that can lookup checkbox scripts524 # Use PATH that can lookup checkbox scripts
523 if job.provider.extra_PYTHONPATH:525 if job.provider.extra_PYTHONPATH:
524 env['PYTHONPATH'] = os.pathsep.join(526 env['PYTHONPATH'] = os.pathsep.join(
525527
=== modified file 'plainbox/plainbox/impl/test_ctrl.py'
--- plainbox/plainbox/impl/test_ctrl.py 2014-06-10 12:51:38 +0000
+++ plainbox/plainbox/impl/test_ctrl.py 2014-06-11 16:22:48 +0000
@@ -533,6 +533,8 @@
533 extra_PYTHONPATH=None,533 extra_PYTHONPATH=None,
534 CHECKBOX_SHARE='CHECKBOX_SHARE',534 CHECKBOX_SHARE='CHECKBOX_SHARE',
535 data_dir='data_dir', units_dir='units_dir'))535 data_dir='data_dir', units_dir='units_dir'))
536 # Mock the default flags (empty set)
537 self.job.get_flag_set.return_value = frozenset()
536 # Create mocked config.538 # Create mocked config.
537 # Put an empty dictionary of environment overrides539 # Put an empty dictionary of environment overrides
538 # that is expected by get_execution_environment()540 # that is expected by get_execution_environment()
@@ -655,9 +657,18 @@
655 # Call the tested method657 # Call the tested method
656 env = self.ctrl.get_execution_environment(658 env = self.ctrl.get_execution_environment(
657 self.job, self.config, self.NEST_DIR)659 self.job, self.config, self.NEST_DIR)
658 # Ensure that LANG is rese to C.UTF-8660 # Ensure that LANG is reset to C.UTF-8
659 self.assertEqual(env['LANG'], 'C.UTF-8')661 self.assertEqual(env['LANG'], 'C.UTF-8')
660662
663 @mock.patch.dict('os.environ', clear=True, LANG='fake_LANG')
664 def test_get_execution_environment_preserves_LANG_if_requested(self):
665 self.job.get_flag_set.return_value = {'preserve-locale'}
666 # Call the tested method
667 env = self.ctrl.get_execution_environment(
668 self.job, self.config, self.NEST_DIR)
669 # Ensure that LANG is what we mocked it to be
670 self.assertEqual(env['LANG'], 'fake_LANG')
671
661 @mock.patch.dict('os.environ', clear=True, PYTHONPATH='PYTHONPATH')672 @mock.patch.dict('os.environ', clear=True, PYTHONPATH='PYTHONPATH')
662 def test_get_execution_environment_keeps_PYTHONPATH(self):673 def test_get_execution_environment_keeps_PYTHONPATH(self):
663 # Call the tested method674 # Call the tested method
@@ -756,6 +767,8 @@
756 data_dir="data_dir-generator",767 data_dir="data_dir-generator",
757 units_dir="units_dir-generator",768 units_dir="units_dir-generator",
758 CHECKBOX_SHARE='CHECKBOX_SHARE-generator'))769 CHECKBOX_SHARE='CHECKBOX_SHARE-generator'))
770 # Mock the default flags (empty set)
771 self.job.origin.source.job.get_flag_set.return_value = frozenset()
759 PATH = os.pathsep.join([self.NEST_DIR, 'vanilla-path'])772 PATH = os.pathsep.join([self.NEST_DIR, 'vanilla-path'])
760 expected = [773 expected = [
761 'pkexec', '--user', self.job.user,774 'pkexec', '--user', self.job.user,
762775
=== modified file 'plainbox/plainbox/impl/unit/job.py'
--- plainbox/plainbox/impl/unit/job.py 2014-05-23 13:44:32 +0000
+++ plainbox/plainbox/impl/unit/job.py 2014-06-11 16:22:48 +0000
@@ -309,6 +309,10 @@
309 return self.get_record_value('user')309 return self.get_record_value('user')
310310
311 @property311 @property
312 def flags(self):
313 return self.get_record_value('flags')
314
315 @property
312 def shell(self):316 def shell(self):
313 """317 """
314 Shell that is used to interpret the command318 Shell that is used to interpret the command
@@ -368,6 +372,15 @@
368 else:372 else:
369 return set()373 return set()
370374
375 def get_flag_set(self):
376 """
377 Return a set of flags associated with this job
378 """
379 if self.flags is not None:
380 return {flag for flag in re.split('[\s,]+', self.flags)}
381 else:
382 return set()
383
371 @property384 @property
372 def automated(self):385 def automated(self):
373 """386 """
374387
=== modified file 'plainbox/plainbox/impl/unit/test_job.py'
--- plainbox/plainbox/impl/unit/test_job.py 2014-05-23 13:44:32 +0000
+++ plainbox/plainbox/impl/unit/test_job.py 2014-06-11 16:22:48 +0000
@@ -67,18 +67,21 @@
67 'environ': 'environ-value',67 'environ': 'environ-value',
68 'user': 'user-value',68 'user': 'user-value',
69 'shell': 'shell-value',69 'shell': 'shell-value',
70 'flags': 'flags-value',
70 }, raw_data={71 }, raw_data={
71 'plugin': 'plugin-raw',72 'plugin': 'plugin-raw',
72 'command': 'command-raw',73 'command': 'command-raw',
73 'environ': 'environ-raw',74 'environ': 'environ-raw',
74 'user': 'user-raw',75 'user': 'user-raw',
75 'shell': 'shell-raw',76 'shell': 'shell-raw',
77 'flags': 'flags-raw',
76 })78 })
77 self.assertEqual(job.plugin, "plugin-value")79 self.assertEqual(job.plugin, "plugin-value")
78 self.assertEqual(job.command, "command-value")80 self.assertEqual(job.command, "command-value")
79 self.assertEqual(job.environ, "environ-value")81 self.assertEqual(job.environ, "environ-value")
80 self.assertEqual(job.user, "user-value")82 self.assertEqual(job.user, "user-value")
81 self.assertEqual(job.shell, "shell-value")83 self.assertEqual(job.shell, "shell-value")
84 self.assertEqual(job.flags, "flags-value")
8285
83 def test_properties_default_values(self):86 def test_properties_default_values(self):
84 """87 """
@@ -90,6 +93,7 @@
90 self.assertEqual(job.environ, None)93 self.assertEqual(job.environ, None)
91 self.assertEqual(job.user, None)94 self.assertEqual(job.user, None)
92 self.assertEqual(job.shell, 'bash')95 self.assertEqual(job.shell, 'bash')
96 self.assertEqual(job.flags, None)
9397
94 def test_checksum_smoke(self):98 def test_checksum_smoke(self):
95 job1 = JobDefinition({'plugin': 'plugin', 'user': 'root'})99 job1 = JobDefinition({'plugin': 'plugin', 'user': 'root'})
@@ -112,6 +116,14 @@
112 job3 = JobDefinition({'environ': 'a,b,c'})116 job3 = JobDefinition({'environ': 'a,b,c'})
113 self.assertEqual(job3.get_environ_settings(), set(['a', 'b', 'c']))117 self.assertEqual(job3.get_environ_settings(), set(['a', 'b', 'c']))
114118
119 def test_get_flag_set(self):
120 job1 = JobDefinition({})
121 self.assertEqual(job1.get_flag_set(), set())
122 job2 = JobDefinition({'flags': 'a b c'})
123 self.assertEqual(job2.get_flag_set(), set(['a', 'b', 'c']))
124 job3 = JobDefinition({'flags': 'a,b,c'})
125 self.assertEqual(job3.get_flag_set(), set(['a', 'b', 'c']))
126
115127
116class JobDefinitionParsingTests(TestCaseWithParameters):128class JobDefinitionParsingTests(TestCaseWithParameters):
117129

Subscribers

People subscribed via source and target branches