Пример #1
0
def sw_update_strategy_get(context):
    result = model_query(context, models.SwUpdateStrategy). \
        filter_by(deleted=0). \
        first()

    if not result:
        raise exception.NotFound()

    return result
Пример #2
0
    def test_create_sw_update_strategy_no_subclouds(self, mock_db_api,
                                                    mock_context,
                                                    mock_patch_orch_thread):
        mock_context.get_admin_context.return_value = self.ctxt
        mock_db_api.sw_update_strategy_get.side_effect = \
            exceptions.NotFound()
        um = sw_update_manager.SwUpdateManager()
        um.create_sw_update_strategy(self.ctxt, payload=FAKE_SW_UPDATE_DATA)
        mock_db_api.sw_update_strategy_create.assert_called_once()

        expected_calls = [
            mock.call(mock.ANY,
                      None,
                      stage=1,
                      state=consts.STRATEGY_STATE_INITIAL,
                      details=''),
        ]
        mock_db_api.strategy_step_create.assert_has_calls(expected_calls)
Пример #3
0
    def test_create_sw_update_strategy_unknown_sync_status(
            self, mock_db_api, mock_context, mock_patch_orch_thread):
        mock_context.get_admin_context.return_value = self.ctxt
        mock_db_api.sw_update_strategy_get.side_effect = \
            exceptions.NotFound()

        # Will be patched
        fake_subcloud1 = Subcloud(1,
                                  'subcloud1',
                                  is_managed=True,
                                  is_online=True)
        fake_status1 = SubcloudStatus()
        # Not patched because not managed
        fake_subcloud2 = Subcloud(2,
                                  'subcloud2',
                                  is_managed=False,
                                  is_online=True)
        fake_status2 = SubcloudStatus()
        # Will be patched
        fake_subcloud3 = Subcloud(3,
                                  'subcloud3',
                                  is_managed=True,
                                  is_online=True)
        fake_status3 = SubcloudStatus()
        # Will fail creation because sync status is unknown
        fake_subcloud4 = Subcloud(4,
                                  'subcloud4',
                                  is_managed=True,
                                  is_online=True)
        fake_status4 = SubcloudStatus(sync_status=consts.SYNC_STATUS_UNKNOWN)
        mock_db_api.subcloud_get_all_with_status.return_value = [
            (fake_subcloud1, fake_status1),
            (fake_subcloud2, fake_status2),
            (fake_subcloud3, fake_status3),
            (fake_subcloud4, fake_status4),
        ]

        um = sw_update_manager.SwUpdateManager()
        self.assertRaises(exceptions.BadRequest,
                          um.create_sw_update_strategy,
                          self.ctxt,
                          payload=FAKE_SW_UPDATE_DATA)
Пример #4
0
    def test_create_sw_update_strategy_serial(self, mock_db_api, mock_context,
                                              mock_patch_orch_thread):
        mock_context.get_admin_context.return_value = self.ctxt
        mock_db_api.sw_update_strategy_get.side_effect = \
            exceptions.NotFound()

        # Will be patched
        fake_subcloud1 = Subcloud(1,
                                  'subcloud1',
                                  is_managed=True,
                                  is_online=True)
        fake_status1 = SubcloudStatus()
        # Not patched because not managed
        fake_subcloud2 = Subcloud(2,
                                  'subcloud2',
                                  is_managed=False,
                                  is_online=True)
        fake_status2 = SubcloudStatus()
        # Will be patched
        fake_subcloud3 = Subcloud(3,
                                  'subcloud3',
                                  is_managed=True,
                                  is_online=True)
        fake_status3 = SubcloudStatus()
        # Not patched because patching is in sync
        fake_subcloud4 = Subcloud(4,
                                  'subcloud4',
                                  is_managed=True,
                                  is_online=True)
        fake_status4 = SubcloudStatus(sync_status=consts.SYNC_STATUS_IN_SYNC)
        # Will be patched
        fake_subcloud5 = Subcloud(5,
                                  'subcloud5',
                                  is_managed=True,
                                  is_online=True)
        fake_status5 = SubcloudStatus()
        # Will be patched
        fake_subcloud6 = Subcloud(6,
                                  'subcloud6',
                                  is_managed=True,
                                  is_online=True)
        fake_status6 = SubcloudStatus()

        mock_db_api.subcloud_get_all_with_status.return_value = [
            (fake_subcloud1, fake_status1),
            (fake_subcloud2, fake_status2),
            (fake_subcloud3, fake_status3),
            (fake_subcloud4, fake_status4),
            (fake_subcloud5, fake_status5),
            (fake_subcloud6, fake_status6),
        ]

        um = sw_update_manager.SwUpdateManager()
        data = copy.copy(FAKE_SW_UPDATE_DATA)
        data["subcloud-apply-type"] = consts.SUBCLOUD_APPLY_TYPE_SERIAL
        um.create_sw_update_strategy(self.ctxt, payload=data)
        mock_db_api.sw_update_strategy_create.assert_called_once()

        expected_calls = [
            mock.call(mock.ANY,
                      None,
                      stage=1,
                      state=consts.STRATEGY_STATE_INITIAL,
                      details=''),
            mock.call(mock.ANY,
                      1,
                      stage=2,
                      state=consts.STRATEGY_STATE_INITIAL,
                      details=''),
            mock.call(mock.ANY,
                      3,
                      stage=3,
                      state=consts.STRATEGY_STATE_INITIAL,
                      details=''),
            mock.call(mock.ANY,
                      5,
                      stage=4,
                      state=consts.STRATEGY_STATE_INITIAL,
                      details=''),
            mock.call(mock.ANY,
                      6,
                      stage=5,
                      state=consts.STRATEGY_STATE_INITIAL,
                      details=''),
        ]
        mock_db_api.strategy_step_create.assert_has_calls(expected_calls)