Beispiel #1
0
 def test_get_downloader_forced_udm(self):
     # Setting SYSTEMIMAGE_PYCURL envar to anything else forces the udm
     # downloader.
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         os.environ['SYSTEMIMAGE_PYCURL'] = '0'
         self.assertIsInstance(get_download_manager(), UDMDownloadManager)
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         os.environ['SYSTEMIMAGE_PYCURL'] = 'false'
         self.assertIsInstance(get_download_manager(), UDMDownloadManager)
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         os.environ['SYSTEMIMAGE_PYCURL'] = 'nope'
         self.assertIsInstance(get_download_manager(), UDMDownloadManager)
Beispiel #2
0
 def test_get_downloader_forced_curl(self):
     # Setting SYSTEMIMAGE_PYCURL envar to 1, yes, or true forces the
     # PyCURL downloader.
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         os.environ['SYSTEMIMAGE_PYCURL'] = '1'
         self.assertIsInstance(get_download_manager(), CurlDownloadManager)
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         os.environ['SYSTEMIMAGE_PYCURL'] = 'tRuE'
         self.assertIsInstance(get_download_manager(), CurlDownloadManager)
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         os.environ['SYSTEMIMAGE_PYCURL'] = 'YES'
         self.assertIsInstance(get_download_manager(), CurlDownloadManager)
Beispiel #3
0
 def test_auto_detect_udm(self):
     # If the environment variable is not set, we do auto-detection.  For
     # backward compatibility, if udm is available on the system bus, we
     # use it.
     with reset_envar('SYSTEMIMAGE_PYCURL'):
         if 'SYSTEMIMAGE_PYCURL' in os.environ:
             del os.environ['SYSTEMIMAGE_PYCURL']
         with patch('dbus.SystemBus.get_object') as mock:
             self.assertIsInstance(
                 get_download_manager(), UDMDownloadManager)
         mock.assert_called_once_with(DOWNLOADER_INTERFACE, '/')
Beispiel #4
0
 def test_auto_detect_none_available(self):
     # Again, we're auto-detecting, but in this case, we have neither udm
     # nor pycurl available.
     import systemimage.download
     with ExitStack() as resources:
         resources.enter_context(reset_envar('SYSTEMIMAGE_PYCURL'))
         if 'SYSTEMIMAGE_PYCURL' in os.environ:
             del os.environ['SYSTEMIMAGE_PYCURL']
         mock = resources.enter_context(
             patch('dbus.SystemBus.get_object', side_effect=DBusException))
         resources.enter_context(
             patch.object(systemimage.download, 'pycurl', None))
         self.assertRaises(ImportError, get_download_manager)
         mock.assert_called_once_with(DOWNLOADER_INTERFACE, '/')
Beispiel #5
0
 def test_auto_detect_curl(self):
     # If the environment variable is not set, we do auto-detection.  If udm
     # is not available on the system bus, we use the cURL downloader.
     import systemimage.download
     with ExitStack() as resources:
         resources.enter_context(reset_envar('SYSTEMIMAGE_PYCURL'))
         if 'SYSTEMIMAGE_PYCURL' in os.environ:
             del os.environ['SYSTEMIMAGE_PYCURL']
         mock = resources.enter_context(
             patch('dbus.SystemBus.get_object', side_effect=DBusException))
         resources.enter_context(
             patch.object(systemimage.download, 'pycurl', object()))
         self.assertIsInstance(
             get_download_manager(), CurlDownloadManager)
         mock.assert_called_once_with(DOWNLOADER_INTERFACE, '/')
Beispiel #6
0
    def _start(self):
        """Start the SystemImage service in a subprocess.

        Use the output from dbus-daemon to gather the address and pid of the
        service in the subprocess.  We'll use those in the foreground process
        to talk to our test instance of the service (rather than any similar
        service running normally on the development desktop).
        """
        daemon_exe = find_executable('dbus-daemon')
        if daemon_exe is None:
            print('Cannot find the `dbus-daemon` executable', file=sys.stderr)
            return
        os.environ['DBUS_VERBOSE'] = '1'
        dbus_args = [
            daemon_exe,
            #'/usr/lib/x86_64-linux-gnu/dbus-1.0/debug-build/bin/dbus-daemon',
            '--fork',
            '--config-file=' + str(self.config_path),
            # Return the address and pid on stdout.
            '--print-address=1',
            '--print-pid=1',
            ]
        stdout = subprocess.check_output(dbus_args, bufsize=4096,
                                         universal_newlines=True)
        lines = stdout.splitlines()
        dbus_address = lines[0].strip()
        self.daemon_pid = int(lines[1].strip())
        #print('DBUS_LAUNCH PID:', self.daemon_pid)
        self._stack.callback(self._kill, self.daemon_pid)
        #print("DBUS_SYSTEM_BUS_ADDRESS='{}'".format(dbus_address))
        # Set the service's address into the environment for rendezvous.
        self._stack.enter_context(reset_envar('DBUS_SYSTEM_BUS_ADDRESS'))
        os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = dbus_address
        # Try to start the DBus services.
        for service, command_template, starter, stopper in SERVICES:
            starter(self)