Example #1
0
    def test_update_subcloud_patches_bad_state(self, mock_db_api, mock_context,
                                               mock_threading,
                                               mock_patching_client, mock_os,
                                               mock_sysinv_client):

        mock_os.path.isfile.return_value = True
        fake_subcloud = Subcloud(1,
                                 'subcloud1',
                                 is_managed=True,
                                 is_online=True)
        data = copy.copy(FAKE_STRATEGY_STEP_DATA)
        data['state'] = consts.STRATEGY_STATE_UPDATING_PATCHES
        data['subcloud'] = fake_subcloud
        mock_context.get_admin_context.return_value = self.ctxt
        fake_strategy_step = StrategyStep(**data)
        mock_patching_client.side_effect = FakePatchingClientSubcloudUnknown
        mock_sysinv_client.side_effect = FakeSysinvClientOneLoad
        FakePatchingClientOutOfSync.apply = mock.Mock()
        FakePatchingClientOutOfSync.remove = mock.Mock()
        FakePatchingClientOutOfSync.upload = mock.Mock()
        sw_update_manager.PatchOrchThread.stopped = lambda x: False
        pot = sw_update_manager.PatchOrchThread()
        pot.get_ks_client = mock.Mock()
        pot.update_subcloud_patches(fake_strategy_step)

        mock_db_api.strategy_step_update.assert_called_with(
            mock.ANY,
            fake_strategy_step.subcloud_id,
            state=consts.STRATEGY_STATE_FAILED,
            details=mock.ANY,
            started_at=mock.ANY,
            finished_at=mock.ANY,
        )
Example #2
0
    def test_finish(self, mock_db_api, mock_context, mock_threading,
                    mock_patching_client, mock_os):

        mock_os.path.isfile.return_value = True
        fake_subcloud = Subcloud(1,
                                 'subcloud1',
                                 is_managed=True,
                                 is_online=True)
        data = copy.copy(FAKE_STRATEGY_STEP_DATA)
        data['state'] = consts.STRATEGY_STATE_UPDATING_PATCHES
        data['subcloud'] = fake_subcloud
        mock_context.get_admin_context.return_value = self.ctxt
        fake_strategy_step = StrategyStep(**data)
        mock_patching_client.side_effect = FakePatchingClientFinish
        FakePatchingClientFinish.delete = mock.Mock()
        FakePatchingClientFinish.commit = mock.Mock()
        sw_update_manager.PatchOrchThread.stopped = lambda x: False
        pot = sw_update_manager.PatchOrchThread()
        pot.get_ks_client = mock.Mock()
        pot.finish(fake_strategy_step)

        assert (compare_call_with_unsorted_list(
            FakePatchingClientFinish.delete.call_args_list[0],
            ['DC.5', 'DC.6']))
        assert (compare_call_with_unsorted_list(
            FakePatchingClientFinish.commit.call_args_list[0],
            ['DC.2', 'DC.3']))
        mock_db_api.strategy_step_update.assert_called_with(
            mock.ANY,
            fake_strategy_step.subcloud_id,
            state=consts.STRATEGY_STATE_COMPLETE,
            details=mock.ANY,
            started_at=mock.ANY,
            finished_at=mock.ANY,
        )
    def test_update_subcloud_patches(self, mock_db_api, mock_context,
                                     mock_threading, mock_patching_client,
                                     mock_os, mock_sysinv_client):

        mock_os.path.isfile.return_value = True
        fake_subcloud = Subcloud(1,
                                 'subcloud1',
                                 is_managed=True,
                                 is_online=True)
        data = copy.copy(FAKE_STRATEGY_STEP_DATA)
        data['state'] = consts.STRATEGY_STATE_UPDATING_PATCHES
        data['subcloud'] = fake_subcloud
        data['subcloud_name'] = 'subcloud1'
        mock_context.get_admin_context.return_value = self.ctxt
        fake_strategy_step = StrategyStep(**data)
        mock_patching_client.side_effect = FakePatchingClientOutOfSync
        mock_sysinv_client.side_effect = FakeSysinvClientOneLoad
        FakePatchingClientOutOfSync.apply = mock.Mock()
        FakePatchingClientOutOfSync.remove = mock.Mock()
        FakePatchingClientOutOfSync.upload = mock.Mock()
        sw_update_manager.PatchOrchThread.stopped = lambda x: False
        pot = sw_update_manager.PatchOrchThread()
        pot.get_ks_client = mock.Mock()
        pot.update_subcloud_patches(fake_strategy_step)

        assert (compare_call_with_unsorted_list(
            FakePatchingClientOutOfSync.remove.call_args_list[0],
            ['DC.5', 'DC.6']))
        FakePatchingClientOutOfSync.upload.assert_called_with(
            [consts.PATCH_VAULT_DIR + '/17.07/DC.8.patch'])
        assert (compare_call_with_unsorted_list(
            FakePatchingClientOutOfSync.apply.call_args_list[0],
            ['DC.2', 'DC.3', 'DC.8']))
        mock_db_api.strategy_step_update.assert_called_with(
            mock.ANY,
            fake_strategy_step.subcloud_id,
            state=consts.STRATEGY_STATE_CREATING_STRATEGY,
            details=mock.ANY,
            started_at=mock.ANY,
            finished_at=mock.ANY,
        )