예제 #1
0
    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 == []
예제 #2
0
    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 == []
예제 #3
0
 def cleanup(self):
     yield
     Client.instance_stopall()