Beispiel #1
0
    def prepare_config(self):
        for key in self._pop_config_keys:
            config.pop(key, None)

        config.update(
            {
                # Default to a uniform retry delay of one second
                "agent_http_retry_delay_offset": 0.1,
                "agent_http_retry_delay_factor": 0,
                "shutting_down": False,
                "jobtypes": {},
                "current_assignments": {},
                "agent_id": uuid.uuid4(),
                "agent_http_persistent_connections": False,
                "agent_shutdown_timeout": 3,
                "master": PYFARM_AGENT_MASTER,
                "agent_hostname": os.urandom(self.RAND_LENGTH).encode("hex"),
                "agent_ram": memory.total_ram(),
                "agent_cpus": cpu.total_cpus(),
                "agent_api_port": randint(10000, 50000),
                "free_ram": memory.free_ram(),
                "agent_time_offset": randint(-50, 50),
                "state": choice(AgentState),
                "start": time.time(),
                "agent_pretty_json": False,
                "agent_html_template_reload": True,
                "agent_master_reannounce": randint(5, 15),
            }
        )
 def test_agent_id_not_set(self):
     config.pop("agent_id", None)
     request = self.post(
         data=self.data,
         headers={"User-Agent": config["master_user_agent"]})
     assign = self.instance_class()
     result = assign.render(request)
     self.assertEqual(result, NOT_DONE_YET)
     self.assertTrue(request.finished)
     self.assertEqual(request.responseCode, SERVICE_UNAVAILABLE)
     self.assertEqual(len(request.written), 1)
     self.assertEqual(
         loads(request.written[0])["error"],
         "agent_id has not been set in the config")
    def test_invalid_get_uid_gid_value_pwd(self):
        import pwd  # platform specific import

        config["jobtype_ignore_id_mapping_errors"] = True

        for i, pwd_struct in enumerate(pwd.getpwall()):
            if i == 5:
                break
            self.assertIsNone(
                self.process._get_uid_gid_value(
                    pwd_struct.pw_name + "foo",
                    "username", "get_uid", pwd, "pwd"))

        config.pop("jobtype_ignore_id_mapping_errors")

        for i, pwd_struct in enumerate(pwd.getpwall()):
            if i == 5:
                break
            with self.assertRaises(KeyError):
                self.assertIsNone(
                    self.process._get_uid_gid_value(
                        pwd_struct.pw_name + "foo",
                        "username", "get_uid", pwd, "pwd"))
    def test_invalid_get_uid_gid_value_grp(self):
        import grp  # platform specific import

        config["jobtype_ignore_id_mapping_errors"] = True

        for i, grp_struct in enumerate(grp.getgrall()):
            if i == 5:
                break
            self.assertIsNone(
                self.process._get_uid_gid_value(
                    grp_struct.gr_name + "foo",
                    "group", "get_gid", grp, "grp"))

        config.pop("jobtype_ignore_id_mapping_errors")

        for i, grp_struct in enumerate(grp.getgrall()):
            if i == 5:
                break
            with self.assertRaises(KeyError):
                self.assertIsNone(
                    self.process._get_uid_gid_value(
                        grp_struct.gr_name + "foo",
                        "group", "get_gid", grp, "grp"))