def make_content(self, size=None):
     tmpdir = self.useFixture(TempDirectory()).path
     if size is None:
         size = randint(1024, 2048)
     data = factory.make_bytes(size)
     content_path = os.path.join(tmpdir, "content")
     with open(content_path, "wb") as stream:
         stream.write(data)
     sha256 = hashlib.sha256()
     sha256.update(data)
     return size, sha256.hexdigest(), partial(open, content_path, "rb")
Beispiel #2
0
 def setUp(self):
     """Setup a special database cluster to perform the tests."""
     super().setUp()
     self.datadir = self.useFixture(TempDirectory()).path
     self.cluster = self.useFixture(ClusterFixture(self.datadir))
     self.useFixture(
         RegionConfigurationFixture(
             database_name=self.dbname,
             database_user=None,
             database_pass=None,
             database_host=self.datadir,
         ))
Beispiel #3
0
 def set_up_config(self):
     if self.homedir is None:
         self.homedir = self.useFixture(TempDirectory()).path
     if self.access_log_file is None:
         self.access_log_file = os.path.join(self.homedir,
                                             "nginx.access.log")
     if self.error_log_file is None:
         self.error_log_file = os.path.join(self.homedir, "nginx.error.log")
     self.nginx_file = os.path.join(self.homedir,
                                    os.path.basename(self.NGINX_PATH))
     self.conf_file = os.path.join(self.homedir, "nginx.conf")
     self.pid_file = os.path.join(self.homedir, "nginx.pid")
Beispiel #4
0
 def test_update_metrics(self):
     self.patch(metrics, "GLOBAL_LABELS", {"service_type": "rack"})
     tempdir = self.useFixture(TempDirectory())
     stat = Path(tempdir.path) / "stat"
     stat.write_text(
         dedent("""\
         cpu  111 222 333 444 555 666 7 888 9 11
         cpu0 222 333 444 555 666 777 8 999 1 22
         cpu1 222 333 444 555 666 777 8 999 1 22
         other line
         other line
         """))
     prometheus_metrics = create_metrics(
         node_metrics_definitions(),
         registry=prometheus_client.CollectorRegistry(),
     )
     update_cpu_metrics(prometheus_metrics, path=stat)
     output = prometheus_metrics.generate_latest().decode("ascii")
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="user"} 1.11',
         output)
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="nice"} 2.22',
         output)
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="system"} 3.33',
         output,
     )
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="idle"} 4.44',
         output)
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="iowait"} 5.55',
         output,
     )
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="irq"} 6.66', output)
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="softirq"} 0.07',
         output,
     )
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="steal"} 8.88',
         output,
     )
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="guest"} 0.09',
         output,
     )
     self.assertIn(
         'maas_node_cpu_time{service_type="rack",state="guest_nice"} 0.11',
         output,
     )
Beispiel #5
0
 def set_up_config(self):
     if self.port is None:
         [self.port] = allocate_ports("localhost")
     if self.rndc_port is None:
         [self.rndc_port] = allocate_ports("localhost")
     if self.homedir is None:
         self.homedir = self.useFixture(TempDirectory()).path
     if self.log_file is None:
         self.log_file = os.path.join(self.homedir, "named.log")
     self.named_file = os.path.join(self.homedir,
                                    os.path.basename(self.NAMED_PATH))
     self.conf_file = os.path.join(self.homedir, "named.conf")
     self.rndcconf_file = os.path.join(self.homedir, "rndc.conf")
Beispiel #6
0
    def test_delete_file_disappeared(self):
        real_os_remove = os.remove

        def mock_os_remove(path):
            # remove it twice, so that FileNotFoundError is raised
            real_os_remove(path)
            real_os_remove(path)

        self.patch(os, 'remove', mock_os_remove)
        tmpdir = Path(self.useFixture(TempDirectory()).path)
        file1 = tmpdir / 'histogram_{}.db'.format(self.get_unused_pid())
        file1.touch()
        self.assertIsNone(clean_prometheus_dir(str(tmpdir)))
 def writes_file(self):
     tempdir = Path(self.useFixture(TempDirectory()).path)
     token_info = {
         "token_key": "tk",
         "token_secret": "ts",
         "consumer_key": "ck",
     }
     path = write_token("myhost", token_info, basedir=tempdir)
     self.assertEqual(
         yaml.load(path),
         {"reporting": {
             "maas": token_info
         }},
     )
Beispiel #8
0
    def test_makeService_cleanup_prometheus_dir(self):
        tmpdir = Path(self.useFixture(TempDirectory()).path)
        self.useFixture(
            EnvironmentVariable("prometheus_multiproc_dir", str(tmpdir)))
        pid = os.getpid()
        file1 = tmpdir / "histogram_{}.db".format(pid)
        file1.touch()
        file2 = tmpdir / "histogram_{}.db".format(self.get_unused_pid())
        file2.touch()

        service_maker = ProvisioningServiceMaker("Harry", "Hill")
        service_maker.makeService(Options(), clock=None)
        self.assertTrue(file1.exists())
        self.assertFalse(file2.exists())
Beispiel #9
0
 def test_update_targets_only_runs_when_conf_exists(self):
     # Regression test for LP:1655721
     temp_dir = self.useFixture(TempDirectory()).path
     self.useFixture(ClusterConfigurationFixture(tftp_root=temp_dir))
     mock_ensureService = self.patch(boot_resources.service_monitor,
                                     "ensureService")
     mock_call_and_check = self.patch(boot_resources, "call_and_check")
     mock_path_exists = self.patch(boot_resources.os.path, 'exists')
     mock_path_exists.return_value = False
     boot_resources.update_targets_conf(temp_dir)
     self.assertThat(mock_ensureService, MockCalledOnceWith("tgt"))
     self.assertThat(mock_path_exists,
                     MockCalledOnceWith(os.path.join(temp_dir, 'maas.tgt')))
     self.assertThat(mock_call_and_check, MockNotCalled())
Beispiel #10
0
 def setUp(self):
     super(ConfigFixture, self).setUp()
     # Create a real configuration file, and populate it.
     self.dir = self.useFixture(TempDirectory()).path
     self.filename = path.join(self.dir, "config.yaml")
     with open(self.filename, "wb") as stream:
         yaml.safe_dump(self.config, stream=stream)
     # Export this filename to the environment, so that subprocesses will
     # pick up this configuration. Define the new environment as an
     # instance variable so that users of this fixture can use this to
     # extend custom subprocess environments.
     self.environ = {"MAAS_PROVISIONING_SETTINGS": self.filename}
     for name, value in self.environ.items():
         self.useFixture(EnvironmentVariableFixture(name, value))
    def test_run_scripts_from_metadata_does_nothing_on_empty(self):
        scripts_dir = self.useFixture(TempDirectory()).path
        self.patch(maas_run_remote_scripts, 'run_scripts')
        mock_signal = self.patch(maas_run_remote_scripts, 'signal')
        self.make_index_json(scripts_dir, False, False)

        # Don't need to give the url, creds, or out_dir as we're not running
        # the scripts and sending the results.
        run_scripts_from_metadata(None, None, scripts_dir, None)

        self.assertThat(
            mock_signal,
            MockCalledOnceWith(None, None, 'OK',
                               'All scripts successfully ran'))
Beispiel #12
0
 def setUp(self):
     super().setUp()
     # Create a real configuration file, and populate it.
     self.dir = self.useFixture(TempDirectory()).path
     self.filename = path.join(self.dir, self.name)
     with open(self.filename, "wb") as stream:
         yaml.safe_dump(self.config, stream=stream, encoding="utf-8")
     # Export this filename to the environment, so that subprocesses will
     # pick up this configuration. Define the new environment as an
     # instance variable so that users of this fixture can use this to
     # extend custom subprocess environments.
     self.environ = {self.schema.envvar: self.filename}
     for name, value in self.environ.items():
         self.useFixture(EnvironmentVariableFixture(name, value))
Beispiel #13
0
 def setUp(self):
     super().setUp()
     self.certificates_dir = self.useFixture(TempDirectory()).path
     self.orig_maas_private_key = maas_certificates.MAAS_PRIVATE_KEY
     maas_certificates.MAAS_PRIVATE_KEY = os.path.join(
         self.certificates_dir, "maas.key")
     self.orig_maas_public_key = maas_certificates.MAAS_PUBLIC_KEY
     maas_certificates.MAAS_PUBLIC_KEY = os.path.join(
         self.certificates_dir, "maas.pub")
     self.orig_maas_certificate = maas_certificates.MAAS_CERTIFICATE
     maas_certificates.MAAS_CERTIFICATE = os.path.join(
         self.certificates_dir, "maas.crt")
     maas_certificates._cert_not_before = None
     maas_certificates._cert_not_after = None
     maas_certificates._cert_mtime = None
Beispiel #14
0
    def test_install_dependencies_url_errors(self):
        mock_run_and_check = self.patch(
            maas_run_remote_scripts, 'run_and_check')
        mock_run_and_check.return_value = False
        scripts_dir = self.useFixture(TempDirectory()).path
        scripts = make_scripts(scripts_dir=scripts_dir)
        packages = [factory.make_name('url') for _ in range(3)]
        for script in scripts:
            script['packages'] = {'url': packages}

        self.assertFalse(install_dependencies(scripts))
        for script in scripts:
            self.assertThat(self.mock_output_and_send, MockAnyCall(
                'Downloading and extracting URLs for %s' % script['msg_name'],
                True, status='INSTALLING'))
Beispiel #15
0
    def test_install_dependencies_url_snap(self):
        mock_run_and_check = self.patch(
            maas_run_remote_scripts, 'run_and_check')
        scripts_dir = self.useFixture(TempDirectory()).path
        scripts = make_scripts(scripts_dir=scripts_dir, with_output=False)
        snap_file = os.path.join(scripts[0]['download_path'], 'file.snap')
        open(snap_file, 'w').close()
        with open(scripts[0]['combined_path'], 'w') as output:
            output.write("Saving to: '%s'" % snap_file)
        for script in scripts:
            script['packages'] = {'url': [snap_file]}

        self.assertTrue(install_dependencies(scripts))
        self.assertThat(mock_run_and_check, MockAnyCall(
            ['snap', snap_file], scripts, True, True))
Beispiel #16
0
    def capture(self, proc, timeout=None):
        scripts_dir = Path(self.useFixture(TempDirectory()).path)
        combined_path = scripts_dir.joinpath("combined")
        stdout_path = scripts_dir.joinpath("stdout")
        stderr_path = scripts_dir.joinpath("stderr")

        returncode = maas_api_helper.capture_script_output(
            proc, str(combined_path), str(stdout_path), str(stderr_path),
            timeout)

        return (
            returncode,
            stdout_path.read_text(),
            stderr_path.read_text(),
            combined_path.read_text(),
        )
Beispiel #17
0
 def test_delete_for_nonexistent_processes(self):
     tmpdir = Path(self.useFixture(TempDirectory()).path)
     pid = os.getpid()
     file1 = tmpdir / 'histogram_1.db'
     file1.touch()
     file2 = tmpdir / 'histogram_{}.db'.format(pid)
     file2.touch()
     file3 = tmpdir / 'histogram_{}.db'.format(self.get_unused_pid())
     file3.touch()
     file4 = tmpdir / 'histogram_{}.db'.format(self.get_unused_pid())
     file4.touch()
     clean_prometheus_dir(str(tmpdir))
     self.assertTrue(file1.exists())
     self.assertTrue(file2.exists())
     self.assertFalse(file3.exists())
     self.assertFalse(file4.exists())
    def test_finds_nothing(self):
        bmc_config_path = os.path.join(
            self.useFixture(TempDirectory()).path, "bmc-config.yaml")
        args = MagicMock()
        args.user = factory.make_name("user")
        args.password = factory.make_name("password")
        self.patch(bmc_config.HPMoonshot, "detected").return_value = False
        self.patch(bmc_config.IPMI, "detected").return_value = False
        self.patch(bmc_config.Wedge, "detected").return_value = False

        bmc_config.detect_and_configure(args, bmc_config_path)

        self.assertFalse(os.path.exists(bmc_config_path))
        self.assertThat(bmc_config.HPMoonshot.detected, MockCalledOnce())
        self.assertThat(bmc_config.IPMI.detected, MockCalledOnce())
        self.assertThat(bmc_config.Wedge.detected, MockCalledOnce())
    def test_run_scripts_from_metadata_doesnt_run_tests_on_commiss_fail(self):
        scripts_dir = self.useFixture(TempDirectory()).path
        mock_run_scripts = self.patch(maas_run_remote_scripts, 'run_scripts')
        mock_run_scripts.return_value = random.randint(1, 100)
        mock_signal = self.patch(maas_run_remote_scripts, 'signal')
        index_json = self.make_index_json(scripts_dir)

        # Don't need to give the url, creds, or out_dir as we're not running
        # the scripts and sending the results.
        run_scripts_from_metadata(None, None, scripts_dir, None)

        self.assertThat(
            mock_run_scripts,
            MockCalledOnceWith(None, None, scripts_dir, None,
                               index_json['commissioning_scripts']))
        self.assertThat(mock_signal, MockNotCalled())
Beispiel #20
0
 def setUp(self):
     super(ConfigurationFixtureBase, self).setUp()
     # Create a real configuration file, and populate it.
     self.path = path.join(
         self.useFixture(TempDirectory()).path,
         path.basename(self.configuration.DEFAULT_FILENAME))
     with self.configuration.open_for_update(self.path) as config:
         for key, value in self.options.items():
             setattr(config, key, value)
     # Export this filename to the environment, so that subprocesses will
     # pick up this configuration. Define the new environment as an
     # instance variable so that users of this fixture can use this to
     # extend custom subprocess environments.
     self.environ = {self.configuration.envvar: self.path}
     for name, value in self.environ.items():
         self.useFixture(EnvironmentVariableFixture(name, value))
Beispiel #21
0
    def test_run_script_sets_env(self):
        scripts_dir = self.useFixture(TempDirectory()).path
        script = make_script(scripts_dir=scripts_dir)
        mock_popen = self.patch(maas_run_remote_scripts, 'Popen')

        run_script(script, scripts_dir)

        env = mock_popen.call_args[1]['env']
        self.assertEquals(script['combined_path'], env['OUTPUT_COMBINED_PATH'])
        self.assertEquals(script['stdout_path'], env['OUTPUT_STDOUT_PATH'])
        self.assertEquals(script['stderr_path'], env['OUTPUT_STDERR_PATH'])
        self.assertEquals(script['result_path'], env['RESULT_PATH'])
        self.assertEquals(script['download_path'], env['DOWNLOAD_PATH'])
        self.assertEquals(str(script['timeout_seconds']), env['RUNTIME'])
        self.assertEquals(str(script['has_started']), env['HAS_STARTED'])
        self.assertIn('PATH', env)
Beispiel #22
0
    def test_run_and_check_ignores_errors(self):
        scripts_dir = self.useFixture(TempDirectory()).path
        scripts = make_scripts(scripts_dir=scripts_dir, with_output=False)
        script = scripts[0]

        self.assertTrue(run_and_check(
            ['/bin/bash', '-c', 'echo %s;echo %s >&2;false' % (
                script['stdout'], script['stderr'])],
            scripts, False))
        self.assertEquals(
            '%s\n' % script['stdout'], open(script['stdout_path'], 'r').read())
        self.assertEquals(
            '%s\n' % script['stderr'], open(script['stderr_path'], 'r').read())
        self.assertEquals(
            '%s\n%s\n' % (script['stdout'], script['stderr']),
            open(script['combined_path'], 'r').read())
Beispiel #23
0
    def test_run_fio_writes_yaml_file(self):
        tmp_path = Path(self.useFixture(TempDirectory()).path)
        result_path = tmp_path.joinpath("results.yaml")
        self.patch(os, "environ", {"RESULT_PATH": result_path})
        rand_read_bw = random.randint(1000, 1000000000)
        rand_read_iops = random.randint(1000, 1000000000)
        rand_read_output = self.read_output_template.format(
            bw=rand_read_bw, iops=rand_read_iops).encode()
        seq_read_bw = random.randint(1000, 1000000000)
        seq_read_iops = random.randint(1000, 1000000000)
        seq_read_output = self.read_output_template.format(
            bw=seq_read_bw, iops=seq_read_iops).encode()
        rand_write_bw = random.randint(1000, 1000000000)
        rand_write_iops = random.randint(1000, 1000000000)
        rand_write_output = self.write_output_template.format(
            bw=rand_write_bw, iops=rand_write_iops).encode()
        seq_write_bw = random.randint(1000, 1000000000)
        seq_write_iops = random.randint(1000, 1000000000)
        seq_write_output = self.write_output_template.format(
            bw=seq_write_bw, iops=seq_write_iops).encode()
        self.mock_check_output.side_effect = [
            rand_read_output,
            seq_read_output,
            rand_write_output,
            seq_write_output,
        ]

        fio.run_fio(factory.make_name("blockdevice"))

        with open(result_path, "r") as results_file:
            results = yaml.safe_load(results_file)

        self.assertDictEqual(
            {
                "results": {
                    "random_read": "%s KB/s" % rand_read_bw,
                    "random_read_iops": rand_read_iops,
                    "sequential_read": "%s KB/s" % seq_read_bw,
                    "sequential_read_iops": seq_read_iops,
                    "random_write": "%s KB/s" % rand_write_bw,
                    "random_write_iops": rand_write_iops,
                    "sequential_write": "%s KB/s" % seq_write_bw,
                    "sequential_write_iops": seq_write_iops,
                }
            },
            results,
        )
Beispiel #24
0
    def test_run_script_errors_with_bad_param(self):
        fake_block_devices = [{
            'MODEL': factory.make_name('model'),
            'SERIAL': factory.make_name('serial'),
            } for _ in range(3)
        ]
        mock_get_block_devices = self.patch(
            maas_run_remote_scripts, 'get_block_devices')
        mock_get_block_devices.return_value = fake_block_devices
        testing_block_device_model = factory.make_name('model')
        testing_block_device_serial = factory.make_name('serial')
        scripts_dir = self.useFixture(TempDirectory()).path
        script = make_script(scripts_dir=scripts_dir)
        script['parameters'] = {'storage': {
            'type': 'storage',
            'argument_format': '{bad}',
            'value': {
                'model': testing_block_device_model,
                'serial': testing_block_device_serial,
            },
        }}

        self.assertFalse(run_script(script, scripts_dir))

        expected_output = (
            "Unable to run '%s': Storage device '%s' with serial '%s' not "
            'found!\n\n'
            "This indicates the storage device has been removed or "
            "the OS is unable to find it due to a hardware failure. "
            "Please re-commission this node to re-discover the "
            "storage devices, or delete this device manually.\n\n"
            'Given parameters:\n%s\n\n'
            'Discovered storage devices:\n%s\n' % (
                script['name'],
                testing_block_device_model, testing_block_device_serial,
                str(script['parameters']), str(fake_block_devices))
        )
        expected_output = expected_output.encode()
        self.assertThat(self.mock_output_and_send, MockCallsMatch(
            call('Starting %s' % script['msg_name'], **self.args),
            call(
                'Failed to execute %s: 2' % script['msg_name'], exit_status=2,
                files={
                    script['combined_name']: expected_output,
                    script['stderr_name']: expected_output,
                }, **self.args),
        ))
    def test_register_machine(self):
        token_info = {
            "token_key": "tk",
            "token_secret": "ts",
            "consumer_key": "ck",
        }
        mock_geturl = self.mock_geturl([{"system_id": "abcde"}, token_info])
        mock_node = self.patch(maas_run_scripts.platform, "node")
        mock_node.return_value = "myhost"
        tempdir = self.useFixture(TempDirectory()).path

        main([
            "register-machine",
            "--base-dir",
            tempdir,
            "http://mymaas.example.com:5240/MAAS",
            "foo:bar:baz",
        ])
        mock_geturl.assert_has_calls(
            [
                call(
                    "http://mymaas.example.com:5240/MAAS/api/2.0/machines/",
                    credentials=Credentials.from_string("foo:bar:baz"),
                    data=ANY,
                    headers=ANY,
                    retry=False,
                ),
                call(
                    "http://mymaas.example.com:5240/MAAS/api/2.0/machines/abcde/?op=get_token",
                    credentials=Credentials.from_string("foo:bar:baz"),
                    retry=False,
                ),
            ],
            any_order=True,
        )
        mock_node.assert_called_once()
        creds_yaml = yaml.load(
            (Path(tempdir) / "myhost-creds.yaml").read_text())
        info = creds_yaml["reporting"]["maas"]
        self.assertEqual("tk", info["token_key"])
        self.assertEqual("ts", info["token_secret"])
        self.assertEqual("ck", info["consumer_key"])
        self.assertEqual(
            "http://mymaas.example.com:5240/MAAS/metadata/status/abcde",
            info["endpoint"],
        )
Beispiel #26
0
    def test_load_init_command_snap(self):
        from provisioningserver import maas_certificates

        certificates_dir = self.useFixture(TempDirectory()).path
        maas_certificates.MAAS_PRIVATE_KEY = os.path.join(
            certificates_dir, "maas.key")
        maas_certificates.MAAS_PUBLIC_KEY = os.path.join(
            certificates_dir, "maas.pub")
        maas_certificates.MAAS_CERTIFICATE = os.path.join(
            certificates_dir, "maas.crt")
        environ = {"SNAP": "snap-path"}
        self.patch(os, "environ", environ)
        parser = ArgumentParser()
        cli.register_cli_commands(parser)
        subparser = parser.subparsers.choices.get("init")
        self.assertIsInstance(subparser.get_default("execute"),
                              snappy.cmd_init)
Beispiel #27
0
    def test_install_dependencies_apt_errors(self):
        mock_run_and_check = self.patch(
            maas_run_remote_scripts, 'run_and_check')
        mock_run_and_check.return_value = False
        scripts_dir = self.useFixture(TempDirectory()).path
        scripts = make_scripts(scripts_dir=scripts_dir, with_output=False)
        packages = [factory.make_name('apt_pkg') for _ in range(3)]
        for script in scripts:
            script['packages'] = {'apt': packages}

        self.assertFalse(install_dependencies(scripts))
        for script in scripts:
            self.assertThat(self.mock_output_and_send, MockAnyCall(
                'Installing apt packages for %s' % script['msg_name'],
                True, status='INSTALLING'))
            self.assertThat(mock_run_and_check, MockCalledOnceWith(
                ['apt-get', '-qy', 'install'] + packages, scripts, True, True))
Beispiel #28
0
    def make_tarball(self, location, contents):
        """Create a tarball containing the given files.

        :param location: Path to a directory where the tarball can be stored.
        :param contents: A dict mapping file names to file contents.  Where
            the value is `None`, the file will contain arbitrary data.
        :return: Path to a gzip-compressed tarball.
        """
        tarball = os.path.join(location, "%s.tar.gz" % self.make_name())
        with TempDirectory() as working_dir:
            source = working_dir.path
            for name, content in contents.items():
                self.make_file(source, name, content)

            subprocess.check_call(["tar", "-C", source, "-czf", tarball, "."])

        return tarball
Beispiel #29
0
    def test_run_fio_writes_yaml_file(self):
        tmp_path = Path(self.useFixture(TempDirectory()).path)
        result_path = tmp_path.joinpath('results.yaml')
        self.patch(os, 'environ', {'RESULT_PATH': result_path})
        rand_read_bw = random.randint(1000, 1000000000)
        rand_read_iops = random.randint(1000, 1000000000)
        rand_read_output = self.read_output_template.format(
            bw=rand_read_bw, iops=rand_read_iops).encode()
        seq_read_bw = random.randint(1000, 1000000000)
        seq_read_iops = random.randint(1000, 1000000000)
        seq_read_output = self.read_output_template.format(
            bw=seq_read_bw, iops=seq_read_iops).encode()
        rand_write_bw = random.randint(1000, 1000000000)
        rand_write_iops = random.randint(1000, 1000000000)
        rand_write_output = self.write_output_template.format(
            bw=rand_write_bw, iops=rand_write_iops).encode()
        seq_write_bw = random.randint(1000, 1000000000)
        seq_write_iops = random.randint(1000, 1000000000)
        seq_write_output = self.write_output_template.format(
            bw=seq_write_bw, iops=seq_write_iops).encode()
        self.mock_check_output.side_effect = [
            rand_read_output,
            seq_read_output,
            rand_write_output,
            seq_write_output,
        ]

        fio.run_fio(factory.make_name('blockdevice'))

        with open(result_path, 'r') as results_file:
            results = yaml.safe_load(results_file)

        self.assertDictEqual(
            {
                'results': {
                    'random_read': '%s KB/s' % rand_read_bw,
                    'random_read_iops': rand_read_iops,
                    'sequential_read': '%s KB/s' % seq_read_bw,
                    'sequential_read_iops': seq_read_iops,
                    'random_write': '%s KB/s' % rand_write_bw,
                    'random_write_iops': rand_write_iops,
                    'sequential_write': '%s KB/s' % seq_write_bw,
                    'sequential_write_iops': seq_write_iops,
                }
            }, results)
Beispiel #30
0
    def test_run_script_errors_bad_params_on_unexecutable_script_no_errno(
            self):
        # Regression test for LP:1669246
        scripts_dir = self.useFixture(TempDirectory()).path
        script = make_script(scripts_dir=scripts_dir)
        self.mock_capture_script_output.side_effect = OSError()

        self.assertFalse(run_script(script, scripts_dir))

        self.assertThat(self.mock_output_and_send, MockCallsMatch(
            call('Starting %s' % script['msg_name'], **self.args),
            call(
                'Failed to execute %s: 2' % script['msg_name'], exit_status=2,
                files={
                    script['combined_name']: b'Unable to execute script',
                    script['stderr_name']: b'Unable to execute script',
                }, **self.args),
        ))