コード例 #1
0
    def test_run_test_environment_task(self):
        """
        Test that we can start tests in the test environment
        """
        test_id = '34fef34fsdf'

        name = 'livetest-pythonserver-{}'.format(test_id)

        container = GunicornDockerRunner(
            name=name, image='adsabs/pythonsimpleserver:v1.0.0')
        container.start()

        run_test_in_environment(test_id=test_id,
                                test_services=['adsrex'],
                                api_name=name)
コード例 #2
0
 def setUp(self):
     """
     Setup the tests
     """
     self.name = 'livetest-adsws-pythonsimpleserver-{}'.format(gen_salt(5))
     self.builder = GunicornDockerRunner(
         image='adsabs/pythonsimpleserver:v1.0.0',
         name=self.name,
     )
     self.builder.start()
     info = self.builder.client.port(
         self.builder.container['Id'],
         80
     )[0]
     self.host = info['HostIp']
     self.port = info['HostPort']
コード例 #3
0
ファイル: test_tasks.py プロジェクト: adsabs/mission-control
    def test_run_test_environment_task(self):
        """
        Test that we can start tests in the test environment
        """
        test_id = '34fef34fsdf'

        name = 'livetest-pythonserver-{}'.format(test_id)

        container = GunicornDockerRunner(
            name=name,
            image='adsabs/pythonsimpleserver:v1.0.0'
        )
        container.start()

        run_test_in_environment(
            test_id=test_id,
            test_services=['adsrex'],
            api_name=name
        )
コード例 #4
0
class TestGunicornDockerRunner(unittest.TestCase):
    """
    Test the docker runner for the Postgres service
    """
    def setUp(self):
        self.name = 'livetest-gunicorn-{}'.format(gen_salt(5))
        self.builder = GunicornDockerRunner(
            image='adsabs/pythonsimpleserver:v1.0.0',
            name=self.name,
        )

    def tearDown(self):
        """
        teardown the containers
        """
        try:
            self.builder.teardown()
        except:
            pass

    def test_is_ready(self):
        """
        Check if the instance is ready
        """

        self.builder.start()

        self.assertTrue(self.builder.running)
        self.assertTrue(self.builder.ready)

        self.builder.teardown()
        self.assertFalse(self.builder.ready)
        self.assertFalse(self.builder.running)
コード例 #5
0
class TestGunicornDockerRunner(unittest.TestCase):
    """
    Test the docker runner for the Postgres service
    """

    def setUp(self):
        self.name = 'livetest-gunicorn-{}'.format(gen_salt(5))
        self.builder = GunicornDockerRunner(
            image='adsabs/pythonsimpleserver:v1.0.0',
            name=self.name,
        )

    def tearDown(self):
        """
        teardown the containers
        """
        try:
            self.builder.teardown()
        except:
            pass

    def test_is_ready(self):
        """
        Check if the instance is ready
        """

        self.builder.start()

        self.assertTrue(self.builder.running)
        self.assertTrue(self.builder.ready)

        self.builder.teardown()
        self.assertFalse(self.builder.ready)
        self.assertFalse(self.builder.running)
コード例 #6
0
class TestTestProvisioner(unittest.TestCase):
    """
    Test the provisioning of the test cluster script
    """

    def setUp(self):
        """
        Setup the tests
        """
        self.name = 'livetest-adsws-pythonsimpleserver-{}'.format(gen_salt(5))
        self.builder = GunicornDockerRunner(
            image='adsabs/pythonsimpleserver:v1.0.0',
            name=self.name,
        )
        self.builder.start()
        info = self.builder.client.port(
            self.builder.container['Id'],
            80
        )[0]
        self.host = info['HostIp']
        self.port = info['HostPort']

    def tearDown(self):
        """
        Teardown the tests
        """
        self.builder.teardown()

    def test_that_the_script_file_is_provisioned(self):
        """
        Tests that the script file is provisioned as we expect it to be
        """
        test_provisioner = TestProvisioner(services=['adsrex'])

        api_url = 'API_URL="http://{host}:{port}"'.format(
            host=self.host,
            port=self.port
        )
        self.assertIn(api_url, test_provisioner.scripts[0])
コード例 #7
0
    def setUp(self, mocked):
        instance = mocked.return_value
        instance.create_container.return_value = {'Id': 'mocked'}
        instance.port.return_value = [{
            'HostIp': '127.0.0.1',
            'HostPort': 1234
        }]
        instance.containers.return_value = [{
            u'Command':
            u'/entrypoint.sh redis-server',
            u'Created':
            1443632967,
            u'Id':
            u'mocked',
            u'Image':
            u'redis',
            u'Labels': {},
            u'Names': [u'/livetest-redis-tLJpZ'],
            u'Ports': [{
                u'PrivatePort': 6379,
                u'Type': u'tcp'
            }],
            u'Status':
            u'Up About a minute'
        }]
        instance.create_host_config.return_value = {
            'PortBindings': {
                '80/tcp': [{
                    'HostPort': '',
                    'HostIp': ''
                }]
            },
            'NetworkMode': 'host'
        }

        self.instance = instance
        self.environment = dict(consul_host='localhost', consul_port=8500)
        self.builder = GunicornDockerRunner(network_mode="host",
                                            environment=self.environment)
コード例 #8
0
    def setUp(self, mocked):
        instance = mocked.return_value
        instance.create_container.return_value = {'Id': 'mocked'}
        instance.port.return_value = [{'HostIp': '127.0.0.1', 'HostPort': 1234}]
        instance.containers.return_value = [
            {
                u'Command': u'/entrypoint.sh redis-server',
                u'Created': 1443632967,
                u'Id': u'mocked',
                u'Image': u'redis',
                u'Labels': {},
                u'Names': [u'/livetest-redis-tLJpZ'],
                u'Ports': [{u'PrivatePort': 6379, u'Type': u'tcp'}],
                u'Status': u'Up About a minute'
            }
        ]
        instance.create_host_config.return_value = {'PortBindings': {
                '80/tcp': [{'HostPort': '', 'HostIp': ''}]
            }, 'NetworkMode': 'host'}

        self.instance = instance
        self.environment = dict(consul_host='localhost', consul_port=8500)
        self.builder = GunicornDockerRunner(network_mode="host",
                                            environment=self.environment)
コード例 #9
0
class TestGunicornDockerRunner(unittest.TestCase):
    """
    Test the docker runner
    """

    @mock.patch('mc.builders.Client')
    def setUp(self, mocked):
        instance = mocked.return_value
        instance.create_container.return_value = {'Id': 'mocked'}
        instance.port.return_value = [{'HostIp': '127.0.0.1', 'HostPort': 1234}]
        instance.containers.return_value = [
            {
                u'Command': u'/entrypoint.sh redis-server',
                u'Created': 1443632967,
                u'Id': u'mocked',
                u'Image': u'redis',
                u'Labels': {},
                u'Names': [u'/livetest-redis-tLJpZ'],
                u'Ports': [{u'PrivatePort': 6379, u'Type': u'tcp'}],
                u'Status': u'Up About a minute'
            }
        ]
        instance.create_host_config.return_value = {'PortBindings': {
                '80/tcp': [{'HostPort': '', 'HostIp': ''}]
            }, 'NetworkMode': 'host'}

        self.instance = instance
        self.environment = dict(consul_host='localhost', consul_port=8500)
        self.builder = GunicornDockerRunner(network_mode="host",
                                            environment=self.environment)

    def test_can_set_consul(self):
        """
        Tests that consul properties get passed correctly
        """
        expected_call = mock.call(
            command=None,
            image=None,
            name=None,
            environment={'consul_host': 'localhost', 'consul_port': 8500},
            host_config={'PortBindings': {
                '80/tcp': [{'HostPort': '', 'HostIp': ''}]
            }, 'NetworkMode': 'host'}
        )

        self.instance.create_container.assert_has_calls(
            [expected_call]
        )

    def test_ready(self):
        """
        Tests the health check of the service
        """

        with mock.patch.object(mc.builders.requests,
                               'get',
                               side_effect=requests.ConnectionError):
            self.assertFalse(self.builder.ready)

        with HTTMock(response_500):
            self.assertFalse(self.builder.ready)

        with HTTMock(response_200):
            self.assertTrue(self.builder.ready)

    def test_can_provision(self):
        """
        Tests that there is a method that allows provisioning
        """
        try:
            self.builder.provision(services=['adsaws'])
        except Exception as e:
            self.fail('Provisioning failed: {}'.format(e))
コード例 #10
0
class TestGunicornDockerRunner(unittest.TestCase):
    """
    Test the docker runner
    """
    @mock.patch('mc.builders.Client')
    def setUp(self, mocked):
        instance = mocked.return_value
        instance.create_container.return_value = {'Id': 'mocked'}
        instance.port.return_value = [{
            'HostIp': '127.0.0.1',
            'HostPort': 1234
        }]
        instance.containers.return_value = [{
            u'Command':
            u'/entrypoint.sh redis-server',
            u'Created':
            1443632967,
            u'Id':
            u'mocked',
            u'Image':
            u'redis',
            u'Labels': {},
            u'Names': [u'/livetest-redis-tLJpZ'],
            u'Ports': [{
                u'PrivatePort': 6379,
                u'Type': u'tcp'
            }],
            u'Status':
            u'Up About a minute'
        }]
        instance.create_host_config.return_value = {
            'PortBindings': {
                '80/tcp': [{
                    'HostPort': '',
                    'HostIp': ''
                }]
            },
            'NetworkMode': 'host'
        }

        self.instance = instance
        self.environment = dict(consul_host='localhost', consul_port=8500)
        self.builder = GunicornDockerRunner(network_mode="host",
                                            environment=self.environment)

    def test_can_set_consul(self):
        """
        Tests that consul properties get passed correctly
        """
        expected_call = mock.call(command=None,
                                  image=None,
                                  name=None,
                                  environment={
                                      'consul_host': 'localhost',
                                      'consul_port': 8500
                                  },
                                  host_config={
                                      'PortBindings': {
                                          '80/tcp': [{
                                              'HostPort': '',
                                              'HostIp': ''
                                          }]
                                      },
                                      'NetworkMode': 'host'
                                  })

        self.instance.create_container.assert_has_calls([expected_call])

    def test_ready(self):
        """
        Tests the health check of the service
        """

        with mock.patch.object(mc.builders.requests,
                               'get',
                               side_effect=requests.ConnectionError):
            self.assertFalse(self.builder.ready)

        with HTTMock(response_500):
            self.assertFalse(self.builder.ready)

        with HTTMock(response_200):
            self.assertTrue(self.builder.ready)

    def test_can_provision(self):
        """
        Tests that there is a method that allows provisioning
        """
        try:
            self.builder.provision(services=['adsaws'])
        except Exception as e:
            self.fail('Provisioning failed: {}'.format(e))
コード例 #11
0
 def setUp(self):
     self.name = 'livetest-gunicorn-{}'.format(gen_salt(5))
     self.builder = GunicornDockerRunner(
         image='adsabs/pythonsimpleserver:v1.0.0',
         name=self.name,
     )
コード例 #12
0
 def setUp(self):
     self.name = 'livetest-gunicorn-{}'.format(gen_salt(5))
     self.builder = GunicornDockerRunner(
         image='adsabs/pythonsimpleserver:v1.0.0',
         name=self.name,
     )