コード例 #1
0
    def test_clusterexec(self):
        """
        Verify the clusterexec.
        """
        for cmd in ('restart', 'upgrade'):
            with contextlib.nested(
                    mock.patch('cherrypy.engine.publish'),
                    mock.patch('commissaire.transport.ansibleapi.Transport'),
                    mock.patch('etcd.Client')) as (_publish, _tp, _store):
                getattr(_tp(), cmd).return_value = (0, {})

                child = {'value': self.etcd_host}
                return_value = MagicMock(_children=[child])
                return_value.leaves = return_value._children

                # store = _store()
                # store.get = MagicMock('get')
                # store.get.side_effect = (
                _publish.side_effect = (
                    [[MagicMock(value=self.etcd_cluster), None]],
                    [[MagicMock(value=self.etcd_cluster), None]],
                    [[return_value, None]],
                    [[return_value, None]],
                    [[return_value, None]],
                    [[return_value, None]],
                    [[return_value, None]],
                )

                clusterexec('default', cmd)

                # One for the cluster, one for the host
                self.assertEquals(6, _publish.call_count)
コード例 #2
0
    def test_clusterexec_stops_on_failure(self):
        """
        Verify the clusterexec will stop on first failure.
        """
        for cmd in ('restart', 'upgrade'):
            with mock.patch(
                    'commissaire.transport.ansibleapi.Transport') as _tp:
                getattr(_tp(), cmd).return_value = (1, {})

                child = {'value': self.etcd_host}
                return_value = MagicMock(_children=[child])
                return_value.leaves = return_value._children

                store = etcd.Client()
                store.get = MagicMock('get')
                store.get.side_effect = (MagicMock(value=self.etcd_cluster),
                                         return_value)
                store.set = MagicMock('set')

                clusterexec('default', cmd, store)

                # One for the cluster, one for the host
                self.assertEquals(2, store.get.call_count)
                # We should have 4 sets for 1 host
                self.assertEquals(3, store.set.call_count)
コード例 #3
0
    def test_clusterexec(self):
        """
        Verify the clusterexec.
        """
        for cmd in ('deploy', 'restart', 'upgrade'):
            with mock.patch(
                    'commissaire.transport.ansibleapi.Transport') as _tp:

                getattr(_tp(), cmd).return_value = (0, {})

                manager = MagicMock(StoreHandlerManager)
                manager.get.return_value = make_new(CLUSTER_WITH_FLAT_HOST)

                manager.list.return_value = make_new(HOSTS)

                clusterexec(manager, 'cluster', cmd)

                # One for the cluster
                self.assertEquals(1, manager.get.call_count)
                # We should have 4 sets for 1 host
                self.assertEquals(4, manager.save.call_count)
コード例 #4
0
    def test_clusterexec_stops_on_failure(self):
        """
        Verify the clusterexec will stop on first failure.
        """
        for cmd in ('deploy', 'restart', 'upgrade'):
            with mock.patch('cherrypy.engine.publish') as _publish, \
                 mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:

                getattr(_tp(), cmd).return_value = (1, {})

                manager = MagicMock(StoreHandlerManager)
                manager.save.side_effect = (make_new(CLUSTER_WITH_FLAT_HOST),
                                            Exception)

                manager.list.return_value = make_new(HOSTS)

                clusterexec(manager, 'default', cmd)

                # One for the cluster
                self.assertEquals(1, manager.get.call_count)
                # We should have 4 sets for 1 host
                self.assertEquals(2, manager.save.call_count)
コード例 #5
0
    def test_clusterexec_stops_on_failure(self):
        """
        Verify the clusterexec will stop on first failure.
        """
        for cmd in ('restart', 'upgrade'):
            with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:
                getattr(_tp(), cmd).return_value = (1, {})

                child = {'value': self.etcd_host}
                return_value = MagicMock(_children=[child])
                return_value.leaves = return_value._children

                store = etcd.Client()
                store.get = MagicMock('get')
                store.get.return_value = return_value
                store.set = MagicMock('set')

                clusterexec('default', cmd, store)

                self.assertEquals(1, store.get.call_count)
                # We should have 4 sets for 1 host
                self.assertEquals(3, store.set.call_count)
コード例 #6
0
    def test_clusterexec(self):
        """
        Verify the clusterexec.
        """
        for cmd in ('restart', 'upgrade'):
            with mock.patch('commissaire.transport.ansibleapi.Transport') as _tp:
                getattr(_tp(), cmd).return_value = (0, {})

                child = {'value': self.etcd_host}
                return_value = MagicMock(_children=[child])
                return_value.leaves = return_value._children

                store = etcd.Client()
                store.get = MagicMock('get')
                store.get.side_effect = (
                    MagicMock(value=self.etcd_cluster), return_value)
                store.set = MagicMock('set')

                clusterexec('default', cmd, store)

                # One for the cluster, one for the host
                self.assertEquals(2, store.get.call_count)
                # We should have 4 sets for 1 host
                self.assertEquals(4, store.set.call_count)