def test_constructor(self, config_d): # Configuration constructor takes an optional directory argument. config = Configuration(config_d) self.assertEqual(config.service.base, 'phablet.example.com') # Passing in a non-directory is not allowed. self.assertRaises(TypeError, Configuration, data_path('config.config_01.ini'))
def test_negative_port_number(self, config_d): # This ini file has a negative port number. shutil.copy(data_path('config.config_08.ini'), os.path.join(config_d, '01_override.ini')) with self.assertRaises(ValueError) as cm: Configuration(config_d) self.assertEqual(cm.exception.args[0], '-1')
def __init__(self, logfile=None, loglevel='info'): self.loglevel = loglevel # Non-public. self._stack = ExitStack() self._stoppers = [] # Public. self.tmpdir = self._stack.enter_context(temporary_directory()) self.config_path = os.path.join(self.tmpdir, 'dbus-system.conf') self.serverdir = self._stack.enter_context(temporary_directory()) self.daemon_pid = None self.mode = 'live' self.udm_certs = '' self.curl_cert = '' self.patcher = None # Set up the dbus-daemon system configuration file. path = data_path('dbus-system.conf.in') with open(path, 'r', encoding='utf-8') as fp: template = fp.read() username = pwd.getpwuid(os.getuid()).pw_name config = template.format(tmpdir=self.tmpdir, user=username) with open(self.config_path, 'w', encoding='utf-8') as fp: fp.write(config) # We need a client.ini file for the subprocess. self.ini_tmpdir = self._stack.enter_context(temporary_directory()) self.ini_vardir = self._stack.enter_context(temporary_directory()) self.ini_logfile = (os.path.join(self.ini_tmpdir, 'client.log') if logfile is None else logfile) self.ini_path = os.path.join(self.tmpdir, 'config.d') makedirs(self.ini_path) self._reset_configs()
def setUp(self): super().setUp() # Patch this method so that we can verify both the value of the flag # that system-image sets and the value that u-d-m's group downloader # records and uses. This is the only thing we can really # automatically test given that e.g. we won't have GSM in development. self._gsm_set_flag = None self._gsm_get_flag = None self._original = None def set_gsm(iface, *, allow_gsm): self._gsm_set_flag = allow_gsm self._original(iface, allow_gsm=allow_gsm) self._gsm_get_flag = iface.isGSMDownloadAllowed() self._resources = ExitStack() try: # Start the HTTP server running, vending files out of our test # data directory. directory = os.path.dirname(data_path('__init__.py')) self._resources.push(make_http_server(directory, 8980)) # Patch the GSM setting method to capture what actually happens. self._original = getattr(UDMDownloadManager, '_set_gsm') self._resources.enter_context(patch( 'systemimage.udm.UDMDownloadManager._set_gsm', set_gsm)) self._resources.callback(setattr, self, '_original', None) except: self._resources.close() raise
def test_both_ports_disabled(self, config_d): # This ini file has both http and https ports disabled. shutil.copy(data_path('config.config_07.ini'), os.path.join(config_d, '01_override.ini')) config = Configuration() with self.assertRaises(ValueError) as cm: config.load(config_d) self.assertEqual(cm.exception.args[0], 'Cannot disable both http and https ports')
def set_mode(self, *, cert_pem=None, service_mode=''): self.mode = service_mode certificate_path = data_path(cert_pem) if USING_PYCURL: self._set_curl_certs(cert_pem, certificate_path) else: self._set_udm_certs(cert_pem, certificate_path) self._reset_configs() self._configure_services()
def test_service_device(self, config_d): # A configuration file could have a [service]device variable, which # takes precedence. shutil.copy(data_path('config.config_11.ini'), os.path.join(config_d, '01_override.ini')) with patch('systemimage.device.check_output', return_value='nexus9'): config = Configuration(config_d) # This gets the [service]device value from the configuration file, # not the output of the hook. self.assertEqual(config.device, 'nexus8')
def setUp(self): super().setUp() self._resources = ExitStack() try: # Start the HTTP server running, vending files out of our test # data directory. directory = os.path.dirname(data_path('__init__.py')) self._resources.push(make_http_server(directory, 8980)) except: self._resources.close() raise
def _configure_services(self): self.stop_children() # Now we have to set up the .service files. We use the Python # executable used to run the tests, executing the entry point as would # happen in a deployed script or virtualenv. for service, command_template, starter, stopper in SERVICES: command = command_template.format(python=sys.executable, self=self) service_file = service + '.service' path = data_path(service_file + '.in') with open(path, 'r', encoding='utf-8') as fp: template = fp.read() config = template.format(command=command) service_path = os.path.join(self.tmpdir, service_file) with open(service_path, 'w', encoding='utf-8') as fp: fp.write(config) self._stoppers.append(stopper) # If the dbus-daemon is running, reload its configuration files. if self.daemon_pid is not None: wait_for_service()
def test_no_version_detail(self, config): shutil.copy(data_path('helpers.config_02.ini'), os.path.join(config.config_d, '00_config.ini')) config.reload() self.assertEqual(version_detail(), {})
def test_version_detail(self, config): shutil.copy(data_path('helpers.config_01.ini'), os.path.join(config.config_d, '00_config.ini')) config.reload() self.assertEqual(version_detail(), dict(ubuntu='123', mako='456', custom='789'))
def setUp(self): self._directory = os.path.dirname(data_path('__init__.py'))