def test_instance_cmds(self, docker_container): image = docker_container[1] myinstance = Client.instance(image) assert myinstance.get_uri().startswith("instance://") print("...Case 2: List instances") instances = Client.instances() assert len(instances) == 1 instances = Client.instances(return_json=True) assert len(instances) == 1 assert isinstance(instances[0], dict) print("...Case 3: Commands to instances") result = Client.execute(myinstance, ["echo", "hello"]) assert result == "hello\n" print("...Case 4: Return value from instance") result = Client.execute(myinstance, "ls /", return_result=True) print(result) assert "tmp\nusr\nvar" in result["message"] assert result["return_code"] == 0 print("...Case 5: Stop instances") myinstance.stop() instances = Client.instances() assert instances == [] myinstance1 = Client.instance(image) myinstance2 = Client.instance(image) assert myinstance1 is not None assert myinstance2 is not None instances = Client.instances() assert len(instances) == 2 Client.instance_stopall() instances = Client.instances() assert instances == []
def test_instance_cmds(self, docker_container): image = docker_container[1] myinstance = Client.instance(image) assert myinstance.get_uri().startswith('instance://') print("...Case 2: List instances") instances = Client.instances() assert len(instances) == 1 instances = Client.instances(return_json=True) assert len(instances) == 1 assert isinstance(instances[0], dict) print("...Case 3: Commands to instances") result = Client.execute(myinstance, ['echo', 'hello']) assert result == 'hello\n' print('...Case 4: Return value from instance') result = Client.execute(myinstance, 'ls /', return_result=True) print(result) assert 'tmp\nusr\nvar' in result['message'] assert result['return_code'] == 0 print("...Case 5: Stop instances") myinstance.stop() instances = Client.instances() assert instances == [] myinstance1 = Client.instance(image) myinstance2 = Client.instance(image) assert myinstance1 is not None assert myinstance2 is not None instances = Client.instances() assert len(instances) == 2 Client.instance_stopall() instances = Client.instances() assert instances == []
def singularity_exists(self): """Check whether an instance exists or not. """ instances = Client.instances(quiet=self.quiet) for instance in instances: if self.pid in instance.name: return True return False
def test_has_no_instances(): instances = Client.instances() assert instances == []
def singularity_rm(self): """Stops and removes an instance. """ Client.instances(self.pid, quiet=self.quiet).stop()
def any_instance(instance_name): instance = Client.instances(instance_name, quiet=True) if type(instance) == spython.instance.Instance: return instance return None