def test_investigator(self):
        """
        Verify the investigator.
        """
        with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:
            _tp().get_info.return_value = (
                0,
                {
                    'os': 'fedora',
                    'cpus': 2,
                    'memory': 11989228,
                    'space': 487652,
                }
            )

            q = Queue()
            client = etcd.Client()
            client.get = MagicMock('get')
            client.get.return_value = MagicMock(value=self.etcd_host)
            client.set = MagicMock('set')
            client.set.return_value = self.etcd_host

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            q.put_nowait((to_investigate, ssh_priv_key))
            investigator(q, client, True)

            self.assertEquals(1, client.get.call_count)
            self.assertEquals(1, client.set.call_count)
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:
            _tp().get_info.return_value = (0, {
                'os': 'fedora',
                'cpus': 2,
                'memory': 11989228,
                'space': 487652,
            })

            q = Queue()
            client = etcd.Client()
            client.get = MagicMock('get')
            client.get.return_value = MagicMock(value=self.etcd_host)
            client.set = MagicMock('set')
            client.set.return_value = self.etcd_host

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            q.put_nowait((to_investigate, ssh_priv_key))
            investigator(q, client, True)

            self.assertEquals(1, client.get.call_count)
            self.assertEquals(1, client.set.call_count)
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp, \
             mock.patch('etcd.Client.get') as _etcd_get, \
             mock.patch('etcd.Client.write') as _etcd_write:

            _tp().get_info.return_value = (
                0,
                {
                    'os': 'fedora',
                    'cpus': 2,
                    'memory': 11989228,
                    'space': 487652,
                }
            )

            q = Queue()

            _etcd_get.return_value = MagicMock(
                'etcd.EtcdResult', value=self.etcd_host)

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            connection_config = {
                'etcd': {
                    'uri': urlparse('http://127.0.0.1:2379'),
                },
                'kubernetes': {
                    'uri': urlparse('http://127.0.0.1:8080'),
                    'token': 'token',
                }
            }

            q.put_nowait((to_investigate, ssh_priv_key, 'root'))
            investigator(q, connection_config, run_once=True)

            self.assertEquals(1, _etcd_get.call_count)
            self.assertEquals(2, _etcd_write.call_count)
Exemple #4
0
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:

            _tp().get_info.return_value = (
                0,
                {
                    'os': 'fedora',
                    'cpus': 2,
                    'memory': 11989228,
                    'space': 487652,
                }
            )

            _tp().bootstrap.return_value = (0, {})

            request_queue = Queue()
            response_queue = MagicMock(Queue)

            to_investigate = {
                'address': '10.0.0.2',
                'ssh_priv_key': 'dGVzdAo=',
                'remote_user': '******'
            }

            manager = MagicMock(StoreHandlerManager)
            manager.get.return_value = Host(**json.loads(self.etcd_host))

            request_queue.put_nowait((
                manager, to_investigate, Cluster.new().__dict__))
            investigator(request_queue, response_queue, run_once=True)

            # Investigator saves *after* bootstrapping.
            self.assertEquals(0, manager.save.call_count)

            self.assertEquals(1, response_queue.put.call_count)
            host, error = response_queue.put.call_args[0][0]
            self.assertEquals(host.status, 'inactive')
            self.assertIsNone(error)
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with contextlib.nested(
                mock.patch('cherrypy.engine.publish'),
                mock.patch('commissaire.transport.ansibleapi.Transport'),
                mock.patch('etcd.Client')) as (_publish, _tp, _store):
            _tp().get_info.return_value = (
                0,
                {
                    'os': 'fedora',
                    'cpus': 2,
                    'memory': 11989228,
                    'space': 487652,
                }
            )

            q = Queue()
            _publish.return_value = [[
                MagicMock('etcd.EtcdResult', value=self.etcd_host), None]]

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            connection_config = {
                'etcd': {
                    'uri': urlparse('http://127.0.0.1:2379'),
                },
                'kubernetes': {
                    'uri': urlparse('http://127.0.0.1:8080'),
                    'token': 'token',
                }
            }

            q.put_nowait((to_investigate, ssh_priv_key))
            investigator(q, connection_config, True)

            self.assertEquals(3, _publish.call_count)
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:

            _tp().get_info.return_value = (
                0,
                {
                    'os': 'fedora',
                    'cpus': 2,
                    'memory': 11989228,
                    'space': 487652,
                }
            )

            q = Queue()

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            connection_config = {
                'etcd': {
                    'uri': urlparse('http://127.0.0.1:2379'),
                },
                'kubernetes': {
                    'uri': urlparse('http://127.0.0.1:8080'),
                    'token': 'token',
                }
            }

            manager = MagicMock(StoreHandlerManager)
            manager.get.return_value = Host(**json.loads(self.etcd_host))

            q.put_nowait((manager, to_investigate, ssh_priv_key, 'root'))
            investigator(q, connection_config, run_once=True)

            self.assertEquals(1, manager.get.call_count)
            self.assertEquals(2, manager.save.call_count)
Exemple #7
0
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:
            _tp().get_info.return_value = (0, {
                'os': 'fedora',
                'cpus': 2,
                'memory': 11989228,
                'space': 487652,
            })

            q = Queue()
            client = etcd.Client()
            client.get = MagicMock('get')
            client.get.return_value = MagicMock(value=self.etcd_host)
            client.set = MagicMock('set')
            client.set.return_value = self.etcd_host

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            connection_config = {
                'etcd': {
                    'uri': urlparse('http://127.0.0.1:2379'),
                },
                'kubernetes': {
                    'uri': urlparse('http://127.0.0.1:8080'),
                    'token': 'token',
                }
            }

            q.put_nowait((to_investigate, ssh_priv_key))
            investigator(q, connection_config, client, True)

            self.assertEquals(1, client.get.call_count)
            self.assertEquals(2, client.set.call_count)
    def test_investigator(self):
        """
        Verify the investigator.
        """
        with contextlib.nested(
                mock.patch('cherrypy.engine.publish'),
                mock.patch('commissaire.transport.ansibleapi.Transport'),
                mock.patch('etcd.Client')) as (_publish, _tp, _store):
            _tp().get_info.return_value = (0, {
                'os': 'fedora',
                'cpus': 2,
                'memory': 11989228,
                'space': 487652,
            })

            q = Queue()
            _publish.return_value = [[
                MagicMock('etcd.EtcdResult', value=self.etcd_host), None
            ]]

            to_investigate = {
                'address': '10.0.0.2',
            }
            ssh_priv_key = 'dGVzdAo='

            connection_config = {
                'etcd': {
                    'uri': urlparse('http://127.0.0.1:2379'),
                },
                'kubernetes': {
                    'uri': urlparse('http://127.0.0.1:8080'),
                    'token': 'token',
                }
            }

            q.put_nowait((to_investigate, ssh_priv_key))
            investigator(q, connection_config, True)

            self.assertEquals(3, _publish.call_count)