예제 #1
0
    def testStatus(self):
        mix = dockermix.ContainerMix('dockermix-startstop.yml')
        mix.build()

        status = mix.status()

        lines = status.split("\n")
        # Skip over the headers
        del (lines[0])
        for line in lines:
            if len(line) > 0:
                self.assertIn(line[14:29].rstrip(),
                              ['test_server_1', 'test_server_2'])
                self.assertEqual(line[67:77].rstrip(), "Running")

        mix.destroy(timeout=1)

        status = mix.status()

        lines = status.split("\n")
        # Skip over the headers
        del (lines[0])
        for line in lines:
            if len(line) > 0:
                self.assertIn(line[14:29].rstrip(),
                              ['test_server_1', 'test_server_2'])
                self.assertEqual(line[67:77].rstrip(), "Destroyed")
예제 #2
0
    def testBuildDockerfile(self):
        mix = dockermix.ContainerMix('dockermix-dockerfile.yml')
        mix.build()
        env = yaml.load(mix.dump())

        for container in env['containers']:
            state = docker.Client().inspect_container(
                env['containers'][container]['container_id'])

            self.assertIsNotNone(state)
            self.assertIn(container, ['test_server_1', 'test_server_2'])

            self.assertEqual(state['State']['ExitCode'], 0)

            if container == 'test_server_1':
                self.assertNotEqual(state['Config']['Image'], 'ubuntu')
                self.assertEqual(state['Path'], 'ns')
                self.assertEqual(state['Args'][0], '-l')

            #elif container == 'test_server_2':
            #  self.assertNotEqual(state['Config']['Image'], 'ubuntu')
            # self.assertEqual(state['Path'], 'ls')
            # self.assertEqual(state['Args'][0], '-l')

        mix.destroy(timeout=1)
예제 #3
0
    def testDestroy(self):
        mix = dockermix.ContainerMix('dockermix.yml')
        mix.build()

        env = yaml.load(mix.dump())
        mix.destroy(timeout=1)

        for container in env['containers']:
            with self.assertRaises(HTTPError) as e:
                docker.Client().inspect_container(
                    env['containers'][container]['container_id'])

            self.assertEqual(str(e.exception), '404 Client Error: Not Found')
예제 #4
0
    def testDependencyEnv(self):
        mix = dockermix.ContainerMix('dockermix-count.yml')

        mix.build()

        # Verify that all three services are running
        env = yaml.load(mix.dump())

        self.assertEqual(len(env['containers']), 4)

        state = docker.Client().inspect_container(
            env['containers']['service_post']['container_id'])
        #self.assertIn("SERVICE1", state['Config']['Env'])

        mix.destroy(timeout=1)
예제 #5
0
    def testCount(self):
        mix = dockermix.ContainerMix('dockermix-count.yml')

        mix.build(180)

        # Verify that all three services are running
        env = yaml.load(mix.dump())

        self.assertEqual(len(env['containers']), 4)

        for container in env['containers']:
            state = docker.Client().inspect_container(
                env['containers'][container]['container_id'])

            #Verify the containers are running
            self.assertTrue(state['State']['Running'])
            self.assertEqual(state['State']['ExitCode'], 0)

        mix.destroy(timeout=1)
예제 #6
0
    def testStart(self):
        mix = dockermix.ContainerMix('dockermix-startstop.yml')
        mix.build()

        mix.stop(timeout=1)
        env = yaml.load(mix.dump())

        for container in env['containers']:
            state = docker.Client().inspect_container(
                env['containers'][container]['container_id'])

            # Verify the containers are stopped
            self.assertFalse(state['State']['Running'])
            self.assertNotEqual(state['State']['ExitCode'], 0)

        mix.start()
        env = yaml.load(mix.dump())

        for container in env['containers']:
            state = docker.Client().inspect_container(
                env['containers'][container]['container_id'])

            # Verify the containers are running again
            self.assertTrue(state['State']['Running'])
            self.assertEqual(state['State']['ExitCode'], 0)

        mix.stop(timeout=1)
        mix.start('test_server_1')

        #Verify that test_server_2 is still stopped
        state = docker.Client().inspect_container(
            env['containers']['test_server_2']['container_id'])
        self.assertFalse(state['State']['Running'])
        self.assertNotEqual(state['State']['ExitCode'], 0)

        #But test_server_1 should now be running
        state = docker.Client().inspect_container(
            env['containers']['test_server_1']['container_id'])
        self.assertTrue(state['State']['Running'])
        self.assertEqual(state['State']['ExitCode'], 0)

        mix.destroy(timeout=1)
예제 #7
0
    def testRequire(self):
        mix = dockermix.ContainerMix('dockermix-require.yml')

        # Verify that it determined the correct start order
        start_order = mix.start_order
        self.assertEqual(start_order[0], 'test_server_2')
        self.assertEqual(start_order[1], 'test_server_1')
        self.assertEqual(start_order[2], 'test_server_3')

        mix.build()

        # Verify that all three services are running
        env = yaml.load(mix.dump())
        for container in env['containers']:
            state = docker.Client().inspect_container(
                env['containers'][container]['container_id'])

            #Verify the containers are running
            self.assertTrue(state['State']['Running'])
            self.assertEqual(state['State']['ExitCode'], 0)

        mix.destroy(timeout=1)
예제 #8
0
 def setUp(self):
     self.mix = dockermix.ContainerMix('dockermix.yml')
     self.mix.build()
예제 #9
0
    def testLoad(self):
        self.mix.save()
        mix = dockermix.ContainerMix(environment='environment.yml')
        env = yaml.load(mix.dump())

        self._configCheck(env)