~allanlesage/+junk/test-here

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/location/fixture_setup.py

  • Committer: Allan LeSage
  • Date: 2015-09-02 18:36:17 UTC
  • mfrom: (180.1.16 trunk)
  • Revision ID: allan.lesage@canonical.com-20150902183617-tmgaw6026ooyt9tt
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
 
21
 
import subprocess
22
 
 
23
21
import fixtures
24
22
 
25
23
from ubuntu_system_tests import config
26
24
from ubuntu_system_tests.helpers import testbed as tb
27
25
 
28
 
STOP_SERVICE_COMMAND = 'service ubuntu-location-service stop'
29
 
START_SERVICE_COMMAND = 'service ubuntu-location-service start'
 
26
STOP_SERVICE_COMMAND = '/sbin/initctl stop ubuntu-location-service'
 
27
START_SERVICE_COMMAND = '/sbin/initctl start ubuntu-location-service'
30
28
UPSTART_OVERRIDE_FILE = '/etc/init/ubuntu-location-service.override'
31
29
 
32
30
 
49
47
    return 'echo \"exec {}\"'.format(command)
50
48
 
51
49
 
52
 
def _put_override_command(command):
53
 
    command = '{} | sudo -A tee {}'.format(command, UPSTART_OVERRIDE_FILE)
54
 
    subprocess.call(command, shell=True, stdout=subprocess.DEVNULL)
55
 
 
56
 
 
57
50
class DummyLocation(fixtures.Fixture):
58
51
    """Fixture to get a default location fix."""
59
52
 
65
58
        super().setUp()
66
59
        config_stack = config.get_device_config_stack()
67
60
        self.password = config_stack.get('device_password')
68
 
        self.stop_location_service()
69
 
        self.start_location_service_with_dummy_fix()
 
61
        with tb.AskPass(self.password):
 
62
            self.stop_location_service()
 
63
            self.start_location_service_with_dummy_fix()
70
64
 
71
65
    def stop_location_service(self):
72
66
        """
73
67
        Stop the already running location service
74
68
        """
75
 
        with tb.AskPass(self.password):
76
 
            tb.run_command_with_sudo(STOP_SERVICE_COMMAND)
77
 
            self.addCleanup(tb.run_command_with_sudo, START_SERVICE_COMMAND)
 
69
        tb.run_command_with_sudo(STOP_SERVICE_COMMAND)
 
70
        self.addCleanup(tb.run_command_with_sudo, START_SERVICE_COMMAND)
78
71
 
79
72
    def start_location_service(self):
80
73
        """
87
80
        """
88
81
        Start the location service with the dummy backend
89
82
        """
90
 
        with tb.AskPass(self.password):
91
 
            tb.make_system_writable(self)
92
 
            self.add_upstart_override()
93
 
            # Cause minimum disruption, just add the override file and
94
 
            # make the system read only, to have a close-to-stock environment.
95
 
            tb.make_system_read_only()
96
 
            self.start_location_service()
 
83
        tb.make_system_writable()
 
84
        self.addCleanup(tb.make_system_read_only)
 
85
        self.add_upstart_override()
 
86
        # Cause minimum disruption, just add the override file and
 
87
        # make the system read only, to have a close-to-stock environment.
 
88
        tb.make_system_read_only()
 
89
        self.start_location_service()
97
90
 
98
91
    def clear_upstart_override_file(self):
99
92
        """Remove the upstart override file to load the dummy backend."""
100
 
        tb.make_system_writable(self)
 
93
        tb.make_system_writable()
101
94
        remove_override_file_command = 'rm {}'.format(UPSTART_OVERRIDE_FILE)
102
95
        tb.run_command_with_sudo(remove_override_file_command)
103
96
 
107
100
        backend."""
108
101
        override_command = _get_location_upstart_job_override_exec_command(
109
102
            self.latitude, self.longitude)
110
 
        _put_override_command(override_command)
 
103
        tb.add_upstart_override_for_job(UPSTART_OVERRIDE_FILE,
 
104
                                        override_command)
111
105
        self.addCleanup(self.clear_upstart_override_file)