This class defines the functions necessary to launch a master in the CLI unit tests.
| 156 | |
| 157 | |
| 158 | class Master(Executable): |
| 159 | """ |
| 160 | This class defines the functions necessary to launch a master in |
| 161 | the CLI unit tests. |
| 162 | """ |
| 163 | count = 0 |
| 164 | |
| 165 | def __init__(self, flags=None): |
| 166 | super(Master, self).__init__() |
| 167 | |
| 168 | if Master.count > 0: |
| 169 | raise CLIException("Creating more than one master" |
| 170 | " is currently not possible") |
| 171 | |
| 172 | if flags is None: |
| 173 | flags = {} |
| 174 | |
| 175 | if "ip" not in flags: |
| 176 | flags["ip"] = TEST_MASTER_IP |
| 177 | if "port" not in flags: |
| 178 | flags["port"] = TEST_MASTER_PORT |
| 179 | if "work_dir" not in flags: |
| 180 | flags["work_dir"] = tempfile.mkdtemp() |
| 181 | |
| 182 | self.flags = flags |
| 183 | self.name = "master" |
| 184 | self.addr = "{ip}:{port}".format(ip=flags["ip"], port=flags["port"]) |
| 185 | self.executable = os.path.join( |
| 186 | CLITestCase.MESOS_BUILD_DIR, |
| 187 | "bin", |
| 188 | "mesos-{name}.sh".format(name=self.name)) |
| 189 | self.shell = True |
| 190 | |
| 191 | def __del__(self): |
| 192 | super(Master, self).__del__() |
| 193 | |
| 194 | if hasattr(self, "flags") and hasattr(self.flags, "work_dir"): |
| 195 | shutil.rmtree(self.flags["work_dir"]) |
| 196 | |
| 197 | # pylint: disable=arguments-differ |
| 198 | def launch(self): |
| 199 | """ |
| 200 | After starting the master, we need to make sure its |
| 201 | reference count is increased. |
| 202 | """ |
| 203 | super(Master, self).launch() |
| 204 | Master.count += 1 |
| 205 | |
| 206 | def kill(self): |
| 207 | """ |
| 208 | After killing the master, we need to make sure its |
| 209 | reference count is decreased. |
| 210 | """ |
| 211 | super(Master, self).kill() |
| 212 | Master.count -= 1 |
| 213 | |
| 214 | |
| 215 | class Agent(Executable): |
no outgoing calls