Example #1
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'
     }]
     self.instance = instance
     self.builder = ConsulDockerRunner(network_mode="host")
Example #2
0
class TestConsulDockerRunner(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'
        }]
        self.instance = instance
        self.builder = ConsulDockerRunner(network_mode="host")

    def test_ready(self):
        """
        Tests the health check of the service and makes sure it is ready
        """
        with HTTMock(response_404):
            self.assertTrue(self.builder.ready)

    def test_not_ready(self):
        """
        Tests the health check of the service and makes sure it is not ready
        """
        with HTTMock(response_500):
            self.assertFalse(self.builder.ready)

    @mock.patch('mc.builders.ConsulDockerRunner.service_provisioner')
    def test_can_provision(self, mocked_consul_runner):
        """
        Tests that there is a method that allows provisioning
        """
        self.builder.provision(services=['adsaws'])

        mocked_consul_runner.assert_has_calls([
            mock.call(services=['adsaws'],
                      container=self.builder,
                      requirements=None),
            mock.call()()
        ])
    def setUp(self):
        """
        Starts a consul node for all the tests
        """
        self.name = 'livetest-consul-{}'.format(gen_salt(5))
        self.builder = ConsulDockerRunner(
            name=self.name,
        )

        self.builder.start()
        self.port = self.builder.client.port(
            self.builder.container['Id'],
            8500
        )[0]['HostPort']
Example #4
0
class TestConsulDockerRunner(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'
            }
        ]
        self.instance = instance
        self.builder = ConsulDockerRunner(network_mode="host")

    def test_ready(self):
        """
        Tests the health check of the service and makes sure it is ready
        """
        with HTTMock(response_404):
            self.assertTrue(self.builder.ready)

    def test_not_ready(self):
        """
        Tests the health check of the service and makes sure it is not ready
        """
        with HTTMock(response_500):
            self.assertFalse(self.builder.ready)

    @mock.patch('mc.builders.ConsulDockerRunner.service_provisioner')
    def test_can_provision(self, mocked_consul_runner):
        """
        Tests that there is a method that allows provisioning
        """
        self.builder.provision(services=['adsaws'])

        mocked_consul_runner.assert_has_calls([
            mock.call(services=['adsaws'], container=self.builder, requirements=None),
            mock.call()()
        ])
Example #5
0
class TestConsulDockerRunner(unittest.TestCase):
    """
    Test the docker runner for the Consul service
    """
    def setUp(self):
        self.name = 'livetest-consul-{}'.format(gen_salt(5))
        self.builder = ConsulDockerRunner(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()
        while not self.builder.ready:
            time.sleep(1)
        self.assertTrue(self.builder.running)
        self.assertTrue(self.builder.ready)

        self.builder.teardown()
        self.assertFalse(self.builder.ready)
        self.assertFalse(self.builder.running)
Example #6
0
class TestConsulDockerRunner(unittest.TestCase):
    """
    Test the docker runner for the Consul service
    """

    def setUp(self):
        self.name = 'livetest-consul-{}'.format(gen_salt(5))
        self.builder = ConsulDockerRunner(
            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()
        while not self.builder.ready:
            time.sleep(1)
        self.assertTrue(self.builder.running)
        self.assertTrue(self.builder.ready)

        self.builder.teardown()
        self.assertFalse(self.builder.ready)
        self.assertFalse(self.builder.running)
Example #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'
         }
     ]
     self.instance = instance
     self.builder = ConsulDockerRunner(network_mode="host")
class TestConsulProvisioner(unittest.TestCase):
    """
    Test the ConsulProvisioner. Use the Docker builder to create the key/value
    store
    """

    def setUp(self):
        """
        Starts a consul node for all the tests
        """
        self.name = 'livetest-consul-{}'.format(gen_salt(5))
        self.builder = ConsulDockerRunner(
            name=self.name,
        )

        self.builder.start()
        self.port = self.builder.client.port(
            self.builder.container['Id'],
            8500
        )[0]['HostPort']

    def tearDown(self):
        """
        Tears down the consul node used by the tests
        """
        self.builder.teardown()

    def test_running_consul(self):
        """
        Checks that consul is started correctly via docker
        """

        while True:
            response = requests.get('http://*****:*****@localhost:5432/adsws"',
            msg='Provisioning is not working: {} != '
                'postgresql+psycopg2://postgres:@localhost:5432/adsws'.format(db_uri)
        )
Example #9
0
 def setUp(self):
     self.name = 'livetest-consul-{}'.format(gen_salt(5))
     self.builder = ConsulDockerRunner(name=self.name, )
Example #10
0
 def setUp(self):
     self.name = 'livetest-consul-{}'.format(gen_salt(5))
     self.builder = ConsulDockerRunner(
         name=self.name,
     )