def test_create_start_log_stop_delete_container(self): arguments = {"image": self.image_id, "command": "/bin/cat /etc/group"} plugin = create_container.DockerCreateContainer( self.conf, "400", {}, "test", arguments) reply = plugin.run() reply_obj = reply['reply_object'] container_id = reply_obj['Id'] print("Container ID " + container_id) arguments = {"container": container_id} plugin = start_container.StartContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() plugin = get_logs_in_container.GetLogContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() print("top") print(str(reply)) plugin = stop_container.StopContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() arguments = {"container": container_id} plugin = delete_container.DeleteContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run()
def test_connect_to_local_port(self): msg_str = str(uuid.uuid4()) arguments = { "image": self.image_id, "command": "/bin/bash -c '/bin/echo %s | " "/bin/nc -l -p 5050'" % msg_str, "ports": [5050] } plugin = create_container.DockerCreateContainer( self.conf, "400", {}, "test", arguments) reply = plugin.run() reply_obj = reply['reply_object'] container_id = reply_obj['Id'] print("Container ID " + container_id) arguments = { "container": container_id, "port_bindings": { 5050: [("0.0.0.0", 5050)] } } plugin = start_container.StartContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() arguments = {} plugin = list_containers.DockerListContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() try: sock = socket.create_connection((self.host, 5050)) received_data = sock.recv(1024).strip() self.assertEqual(received_data, msg_str) finally: arguments = {"container": container_id} plugin = stop_container.StopContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() arguments = {"container": container_id} plugin = delete_container.DeleteContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run()
def test_create_start_list_inspect_stop_delete_container(self): arguments = {"image": self.image_id, "command": "/bin/sleep 60"} plugin = create_container.DockerCreateContainer( self.conf, "400", {}, "test", arguments) reply = plugin.run() reply_obj = reply['reply_object'] container_id = reply_obj['Id'] arguments = {"container": container_id} plugin = start_container.StartContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() arguments = {"container": container_id} plugin = get_container_details.GetContainerDetails( self.conf, "400", {}, "test", arguments) reply = plugin.run() reply_obj = reply['reply_object'] self.assertEqual(reply_obj['Image'], self.image_id) self.assertTrue(reply_obj['State']['Running']) arguments = {} plugin = list_containers.DockerListContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() reply_obj = reply['reply_object'] found_cont = None for cont in reply_obj['containers']: if cont['Id'] == container_id: found_cont = cont self.assertIsNotNone(found_cont) arguments = {"container": container_id} plugin = stop_container.StopContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() arguments = {"container": container_id} plugin = delete_container.DeleteContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run()
def test_create_start_restart_delete_container(self): arguments = {"image": self.image_id, "command": "/bin/sleep 60"} plugin = create_container.DockerCreateContainer( self.conf, "400", {}, "test", arguments) reply = plugin.run() reply_obj = reply['reply_object'] container_id = reply_obj['Id'] arguments = {"container": container_id} plugin = start_container.StartContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() plugin = restart_container.RestartContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() plugin = stop_container.StopContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run() arguments = {"container": container_id} plugin = delete_container.DeleteContainer(self.conf, "400", {}, "test", arguments) reply = plugin.run()