def _images_command_output(self, is_centralized_repository): if is_centralized_repository: command = ["sarus", "images", "--centralized-repository"] else: command = ["sarus", "images"] out = subprocess.check_output(command) lines = util.command_output_without_trailing_new_lines(out) return [line.split() for line in lines]
def test_cpu_affinity(self): image = "alpine:3.8" util.pull_image_if_necessary(is_centralized_repository=False, image=image) command = ["cat", "/proc/self/status"] out = util.command_output_without_trailing_new_lines(subprocess.check_output(command).decode()) host_cpus_allowed_list = self._parse_cpus_allowed_list(out) only_one_cpu_available = len(host_cpus_allowed_list) == 1 if only_one_cpu_available: print("WARNING: skipping CPU affinity test. Only one CPU" " is available, but at least two are required.") return cpu = self._parse_first_cpu(host_cpus_allowed_list) command = ["taskset", "--cpu-list", cpu, "sarus", "run", image, "cat", "/proc/self/status"] out = util.command_output_without_trailing_new_lines(subprocess.check_output(command).decode()) container_cpus_allowed_list = self._parse_cpus_allowed_list(out) self.assertEqual(container_cpus_allowed_list, cpu)
def _get_sarus_warn_output(self): command = ["sarus", "run", "--mpi", self._container_image, "true"] out = subprocess.check_output(command, stderr=subprocess.STDOUT).decode() return util.command_output_without_trailing_new_lines(out)
def _test_command_version(self, command): out = subprocess.check_output(command) lines = util.command_output_without_trailing_new_lines(out) self.assertEqual(len(lines), 1) self.assertTrue(re.match(r"^\d+\.\d+\.\d+(-.+)*$", lines[0]) is not None)
def _test_command_help(self, command): out = subprocess.check_output(command) lines = util.command_output_without_trailing_new_lines(out) self.assertGreater(len(lines), 1) self.assertEqual(lines[0], "Usage: sarus COMMAND")
def _test_command_version(self, command): out = subprocess.check_output(command).decode() lines = util.command_output_without_trailing_new_lines(out) assert len(lines) == 1 assert re.match(r"^\d+\.\d+\.\d+(-.+)*$", lines[0]) is not None \ or lines[0] == "VERSION-NOT-AVAILABLE"