コード例 #1
0
 def setUp(self, mock_rpc):
     super(NotificationAPITestCase, self).setUp()
     self.notification_api = ha_api.NotificationAPI()
     self.req = fakes.HTTPRequest.blank('/v1/notifications',
                                        use_admin_context=True)
     self.context = self.req.environ['masakari.context']
     self.host = fakes_data.create_fake_host(
         name="host_1",
         id=1,
         reserved=False,
         on_maintenance=False,
         type="fake",
         control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1,
         failover_segment_id=uuidsentinel.fake_segment1)
     self.notification = fakes_data.create_fake_notification(
         type="VM",
         id=1,
         payload={
             'event': 'STOPPED',
             'host_status': 'NORMAL',
             'cluster_status': 'ONLINE'
         },
         source_host_uuid=uuidsentinel.fake_host,
         generated_time=NOW,
         status="running",
         notification_uuid=uuidsentinel.fake_notification)
コード例 #2
0
ファイル: test_engine_mgr.py プロジェクト: rkmrHonjo/masakari
    def test_process_notification_reserved_host_failure(
            self, mock_notification_save, mock_host_failure, mock_get_all,
            mock_host_update, mock_host_save, mock_host_obj):
        fake_host = fakes.create_fake_host(reserved=True)
        fake_host.failover_segment = fakes.create_fake_failover_segment(
            recovery_method='reserved_host')
        reserved_host_list = [fake_host]
        mock_get_all.return_value = reserved_host_list
        mock_host_obj.return_value = fake_host

        notification = self._get_compute_host_type_notification()
        mock_host_failure.side_effect = self._fake_notification_workflow()

        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
            'reserved': False,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("finished", notification.status)
        mock_host_failure.assert_called_once_with(
            self.context,
            fake_host.name, fake_host.failover_segment.recovery_method,
            notification.notification_uuid,
            reserved_host_list=reserved_host_list)
コード例 #3
0
ファイル: test_api.py プロジェクト: takanattie/masakari
 def setUp(self, mock_rpc):
     super(NotificationAPITestCase, self).setUp()
     self.notification_api = ha_api.NotificationAPI()
     self.req = fakes.HTTPRequest.blank('/v1/notifications',
                                        use_admin_context=True)
     self.context = self.req.environ['masakari.context']
     self.failover_segment = fakes_data.create_fake_failover_segment(
         name="segment1",
         id=1,
         description="something",
         service_type="COMPUTE",
         recovery_method="auto",
         uuid=uuidsentinel.fake_segment)
     self.host = fakes_data.create_fake_host(
         name="host_1",
         id=1,
         reserved=False,
         on_maintenance=False,
         type="fake",
         control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1)
     self.notification = fakes_data.create_fake_notification(
         type="VM",
         id=1,
         payload={
             'event': 'STOPPED',
             'host_status': 'NORMAL',
             'cluster_status': 'ONLINE'
         },
         source_host_uuid=uuidsentinel.fake_host,
         generated_time=NOW,
         status="running",
         notification_uuid=uuidsentinel.fake_notification)
     self.exception_duplicate = exception.DuplicateNotification(
         host='host_1', type='COMPUTE_HOST')
コード例 #4
0
    def test_host_failure_flow_for_reserved_host_recovery(
            self, _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client
        self.override_config("evacuate_all_instances",
                             True, "host_failure")
        self.override_config("add_reserved_host_to_aggregate",
                             True, "host_failure")

        # create test data
        self.fake_client.servers.create(id="1", host=self.instance_host,
                                        ha_enabled=True)
        self.fake_client.servers.create(id="2", host=self.instance_host)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(id="1", name='fake_agg',
                                           hosts=[self.instance_host])

        # execute DisableComputeServiceTask
        self._test_disable_compute_service()

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list()

        # execute EvacuateInstancesTask
        with mock.patch.object(host_obj.Host, "save") as mock_save:
            instance_list = self._evacuate_instances(
                instance_list, reserved_host=reserved_host)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)

        # execute ConfirmEvacuationTask
        self._test_confirm_evacuate_task(instance_list)
コード例 #5
0
ファイル: test_engine_mgr.py プロジェクト: thaihust/masakari
    def test_process_notification_reserved_host_failure(
            self, mock_notification_save, mock_host_failure, mock_get_all,
            mock_host_update, mock_host_save, mock_host_obj):
        fake_host = fakes.create_fake_host(reserved=True)
        fake_host.failover_segment = fakes.create_fake_failover_segment(
            recovery_method='reserved_host')
        reserved_host_list = [fake_host]
        mock_get_all.return_value = reserved_host_list
        mock_host_obj.return_value = fake_host

        notification = self._get_compute_host_type_notification()
        mock_host_failure.side_effect = self._fake_notification_workflow()

        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
            'reserved': False,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("finished", notification.status)
        mock_host_failure.assert_called_once_with(
            self.context,
            fake_host.name,
            fake_host.failover_segment.recovery_method,
            notification.notification_uuid,
            reserved_host_list=reserved_host_list)
コード例 #6
0
    def test_host_failure_flow_for_reserved_host_recovery(
            self, _mock_novaclient, mock_unlock, mock_lock,
            mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        self.override_config("evacuate_all_instances",
                             True, "host_failure")
        self.override_config("add_reserved_host_to_aggregate",
                             True, "host_failure")

        # create test data
        self.fake_client.servers.create(id="1", host=self.instance_host,
                                        ha_enabled=True)
        self.fake_client.servers.create(id="2", host=self.instance_host)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(id="1", name='fake_agg',
                                           hosts=[self.instance_host])

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list(2)

        # execute EvacuateInstancesTask
        with mock.patch.object(host_obj.Host, "save") as mock_save:
            self._evacuate_instances(
                instance_list, mock_enable_disable,
                reserved_host=reserved_host)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)
コード例 #7
0
    def test_process_notification_type_compute_host_event_stopped(
            self, mock_notification_save, mock_host_failure, mock_get_all,
            mock_host_update, mock_host_save, mock_host_obj,
            mock_notification_get):
        notification = self._get_compute_host_type_notification()
        mock_notification_get.return_value = notification
        mock_host_failure.side_effect = self._fake_notification_workflow()
        fake_host = fakes.create_fake_host()
        mock_get_all.return_value = None
        fake_host.failover_segment = fakes.create_fake_failover_segment()
        mock_host_obj.return_value = fake_host
        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("finished", notification.status)
        mock_host_failure.assert_called_once_with(
            self.context,
            fake_host.name,
            fake_host.failover_segment.recovery_method,
            notification.notification_uuid,
            reserved_host_list=None)
コード例 #8
0
    def test_host_failure_flow_for_RH_recovery(
            self, _mock_notify, _mock_novaclient, mock_unlock, mock_lock,
            mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        self.override_config("evacuate_all_instances",
                             True, "host_failure")
        self.override_config("add_reserved_host_to_aggregate",
                             True, "host_failure")

        # create test data
        self.fake_client.servers.create(id="1", host=self.instance_host,
                                        ha_enabled=True)
        self.fake_client.servers.create(id="2", host=self.instance_host)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(id="1", name='fake_agg',
                                           hosts=[self.instance_host])

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list(2)

        # execute EvacuateInstancesTask
        with mock.patch.object(manager, "update_host_method") as mock_save:
            self._evacuate_instances(
                instance_list, mock_enable_disable,
                reserved_host=reserved_host.name)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call("Disabling compute service on host: 'fake-host'"),
            mock.call("Disabled compute service on host: 'fake-host'", 1.0),
            mock.call('Preparing instances for evacuation'),
            mock.call("Total instances running on failed host 'fake-host' is 2"
                      "", 0.3),
            mock.call("Total HA Enabled instances count: '1'", 0.6),
            mock.call("Total Non-HA Enabled instances count: '1'", 0.7),
            mock.call("All instances (HA Enabled/Non-HA Enabled) should be "
                      "considered for evacuation. Total count is: '2'", 0.8),
            mock.call("Instances to be evacuated are: '1,2'", 1.0),
            mock.call("Start evacuation of instances from failed host "
                      "'fake-host', instance uuids are: '1,2'"),
            mock.call("Enabling reserved host: 'fake-reserved-host'", 0.1),
            mock.call('Add host fake-reserved-host to aggregate fake_agg',
                      0.2),
            mock.call('Added host fake-reserved-host to aggregate fake_agg',
                      0.3),
            mock.call("Evacuation of instance started: '1'", 0.5),
            mock.call("Evacuation of instance started: '2'", 0.5),
            mock.call("Successfully evacuate instances '1,2' from host "
                      "'fake-host'", 0.7),
            mock.call('Evacuation process completed!', 1.0)
        ])
コード例 #9
0
    def test_host_failure_flow_ignores_conflict_error(
            self, mock_log, _mock_notify, _mock_novaclient, mock_add_host,
            mock_unlock, mock_lock, mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        mock_add_host.side_effect = exception.Conflict
        self.override_config("add_reserved_host_to_aggregate",
                             True, "host_failure")

        # create test data
        self.fake_client.servers.create(id="1", host=self.instance_host,
                                        ha_enabled=True)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(id="1", name='fake_agg',
                                           hosts=[self.instance_host,
                                                  reserved_host.name])
        expected_msg_format = ("Host '%(reserved_host)s' already has been "
                               "added to aggregate '%(aggregate)s'.") % {
            'reserved_host': 'fake-reserved-host', 'aggregate': 'fake_agg'
        }

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list(1)

        # execute EvacuateInstancesTask
        with mock.patch.object(manager, "update_host_method") as mock_save:
            self._evacuate_instances(
                instance_list, mock_enable_disable,
                reserved_host=reserved_host.name)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)
            mock_log.info.assert_any_call(expected_msg_format)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call("Disabling compute service on host: 'fake-host'"),
            mock.call("Disabled compute service on host: 'fake-host'", 1.0),
            mock.call('Preparing instances for evacuation'),
            mock.call("Total instances running on failed host 'fake-host' is 1"
                      "", 0.3),
            mock.call("Total HA Enabled instances count: '1'", 0.6),
            mock.call("Instances to be evacuated are: '1'", 1.0),
            mock.call("Start evacuation of instances from failed host "
                      "'fake-host', instance uuids are: '1'"),
            mock.call("Enabling reserved host: 'fake-reserved-host'", 0.1),
            mock.call('Add host fake-reserved-host to aggregate fake_agg',
                      0.2),
            mock.call("Host 'fake-reserved-host' already has been added to "
                      "aggregate 'fake_agg'.", 1.0),
            mock.call("Evacuation of instance started: '1'", 0.5),
            mock.call("Successfully evacuate instances '1' from host "
                      "'fake-host'", 0.7),
            mock.call('Evacuation process completed!', 1.0)
        ])
コード例 #10
0
ファイル: test_engine_mgr.py プロジェクト: rkmrHonjo/masakari
 def test_process_notification_type_process_event_started(
         self, mock_process_failure, mock_notification_save,
         mock_host_save, mock_host_obj):
     notification = self._get_process_type_notification()
     notification.payload['event'] = 'started'
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("finished", notification.status)
     self.assertFalse(mock_process_failure.called)
コード例 #11
0
ファイル: test_engine_mgr.py プロジェクト: rkmrHonjo/masakari
 def test_process_notification_type_process_recovery_failure(
         self, mock_notification_save, mock_process_failure,
         mock_host_save, mock_host_obj):
     notification = self._get_process_type_notification()
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     mock_process_failure.side_effect = self._fake_notification_workflow(
         exc=exception.ProcessRecoveryFailureException)
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("error", notification.status)
コード例 #12
0
ファイル: test_engine_mgr.py プロジェクト: thaihust/masakari
 def test_process_notification_type_process_event_started(
         self, mock_process_failure, mock_notification_save, mock_host_save,
         mock_host_obj):
     notification = self._get_process_type_notification()
     notification.payload['event'] = 'started'
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("finished", notification.status)
     self.assertFalse(mock_process_failure.called)
コード例 #13
0
ファイル: test_engine_mgr.py プロジェクト: thaihust/masakari
 def test_process_notification_type_process_recovery_failure(
         self, mock_notification_save, mock_process_failure, mock_host_save,
         mock_host_obj):
     notification = self._get_process_type_notification()
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     mock_process_failure.side_effect = self._fake_notification_workflow(
         exc=exception.ProcessRecoveryFailureException)
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("error", notification.status)
コード例 #14
0
 def test_process_notification_type_process_skip_recovery(
         self, mock_notification_save, mock_process_failure, mock_host_save,
         mock_host_obj, mock_notification_get):
     notification = self._get_process_type_notification()
     mock_notification_get.return_value = notification
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     mock_process_failure.side_effect = self._fake_notification_workflow(
         exc=exception.SkipProcessRecoveryException)
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("finished", notification.status)
コード例 #15
0
ファイル: test_hosts.py プロジェクト: takanattie/masakari
 def setUp(self):
     super(HostTestCase, self).setUp()
     self._set_up()
     self.failover_segment = fakes_data.create_fake_failover_segment(
         name="segment1", id=1, description="failover_segment for compute",
         service_type="COMPUTE", recovery_method="auto",
         uuid=uuidsentinel.fake_segment
     )
     self.host = fakes_data.create_fake_host(
         name="host_1", id=1, reserved=False, on_maintenance=False,
         type="fake", control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1,
         failover_segment=self.failover_segment
     )
     self.host_2 = fakes_data.create_fake_host(
         name="host_2", id=2, reserved=False, on_maintenance=False,
         type="fake", control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_2,
         failover_segment=self.failover_segment
     )
     self.host_list = [self.host, self.host_2]
     self.host_list_obj = _make_hosts_list(self.host_list)
コード例 #16
0
ファイル: test_engine_mgr.py プロジェクト: thaihust/masakari
 def test_process_notification_type_process_event_stopped(
         self, mock_notification_save, mock_process_failure, mock_host_save,
         mock_host_obj):
     notification = self._get_process_type_notification()
     mock_process_failure.side_effect = self._fake_notification_workflow()
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("finished", notification.status)
     mock_process_failure.assert_called_once_with(
         self.context, notification.payload.get('process_name'),
         fake_host.name, notification.notification_uuid)
コード例 #17
0
ファイル: test_engine_mgr.py プロジェクト: rkmrHonjo/masakari
 def test_process_notification_type_process_event_stopped(
         self, mock_notification_save, mock_process_failure,
         mock_host_save, mock_host_obj):
     notification = self._get_process_type_notification()
     mock_process_failure.side_effect = self._fake_notification_workflow()
     fake_host = fakes.create_fake_host()
     mock_host_obj.return_value = fake_host
     self.engine.process_notification(self.context,
                                      notification=notification)
     self.assertEqual("finished", notification.status)
     mock_process_failure.assert_called_once_with(
         self.context, notification.payload.get('process_name'),
         fake_host.name,
         notification.notification_uuid)
コード例 #18
0
ファイル: test_api.py プロジェクト: openstack/masakari
    def test_get_all(self, mock_get, mock_get_all):
        mock_get.return_value = self.failover_segment
        fake_host = fakes_data.create_fake_host(
            name="host_2", id=2, reserved=False, on_maintenance=False,
            type="fake", control_attributes="fake-control_attributes",
            uuid=uuidsentinel.fake_host_2,
            failover_segment_id=uuidsentinel.fake_segment1
        )
        fake_host_list = [self.host, fake_host]
        mock_get_all.return_value = fake_host_list

        result = self.host_api.get_all(self.context,
                                       filters=None, sort_keys=['created_at'],
                                       sort_dirs=['desc'], limit=None,
                                       marker=None)
        for i in range(len(result)):
            self._assert_host_data(
                fake_host_list[i], _make_host_obj(result[i]))
コード例 #19
0
ファイル: test_engine_mgr.py プロジェクト: rkmrHonjo/masakari
    def test_process_notification_type_compute_host_recovery_exception(
            self, mock_notification_save, mock_host_failure, mock_get_all,
            mock_host_update, mock_host_save, mock_host_obj):
        notification = self._get_compute_host_type_notification()
        fake_host = fakes.create_fake_host()
        mock_get_all.return_value = None
        fake_host.failover_segment = fakes.create_fake_failover_segment()
        mock_host_obj.return_value = fake_host
        mock_host_failure.side_effect = self._fake_notification_workflow(
            exc=exception.HostRecoveryFailureException)
        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("error", notification.status)
コード例 #20
0
ファイル: test_engine_mgr.py プロジェクト: thaihust/masakari
    def test_process_notification_type_compute_host_recovery_exception(
            self, mock_notification_save, mock_host_failure, mock_get_all,
            mock_host_update, mock_host_save, mock_host_obj):
        notification = self._get_compute_host_type_notification()
        fake_host = fakes.create_fake_host()
        mock_get_all.return_value = None
        fake_host.failover_segment = fakes.create_fake_failover_segment()
        mock_host_obj.return_value = fake_host
        mock_host_failure.side_effect = self._fake_notification_workflow(
            exc=exception.HostRecoveryFailureException)
        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("error", notification.status)
コード例 #21
0
ファイル: test_api.py プロジェクト: rkmrHonjo/masakari
 def setUp(self):
     super(HostAPITestCase, self).setUp()
     self.host_api = ha_api.HostAPI()
     self.req = fakes.HTTPRequest.blank(
         '/v1/segments/%s/hosts' % uuidsentinel.fake_segment,
         use_admin_context=True)
     self.context = self.req.environ['masakari.context']
     self.failover_segment = fakes_data.create_fake_failover_segment(
         name="segment1", id=1, description="something",
         service_type="COMPUTE", recovery_method="auto",
         uuid=uuidsentinel.fake_segment
     )
     self.host = fakes_data.create_fake_host(
         name="host_1", id=1, reserved=False, on_maintenance=False,
         type="fake", control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1,
         failover_segment_id=uuidsentinel.fake_segment1
     )
コード例 #22
0
    def test_host_failure_flow_ignores_conflict_error(self, mock_log,
                                                      _mock_novaclient,
                                                      mock_add_host,
                                                      mock_unlock, mock_lock,
                                                      mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        mock_add_host.side_effect = exception.Conflict
        self.override_config("add_reserved_host_to_aggregate", True,
                             "host_failure")

        # create test data
        self.fake_client.servers.create(id="1",
                                        host=self.instance_host,
                                        ha_enabled=True)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(
            id="1",
            name='fake_agg',
            hosts=[self.instance_host, reserved_host.name])
        expected_msg_format = "Host '%(reserved_host)s' already has been " \
                              "added to aggregate '%(aggregate)s'."
        expected_msg_params = {
            'aggregate': 'fake_agg',
            'reserved_host': u'fake-reserved-host'
        }

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list(1)

        # execute EvacuateInstancesTask
        with mock.patch.object(host_obj.Host, "save") as mock_save:
            self._evacuate_instances(instance_list,
                                     mock_enable_disable,
                                     reserved_host=reserved_host)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)
            mock_log.info.assert_any_call(expected_msg_format,
                                          expected_msg_params)
コード例 #23
0
ファイル: test_engine_mgr.py プロジェクト: rkmrHonjo/masakari
    def test_process_notification_host_failure_without_reserved_hosts(
            self, mock_notification_save, mock_get_all,
            mock_host_update, mock_host_save, mock_host_obj):
        reserved_host_list = []
        mock_get_all.return_value = reserved_host_list

        fake_host = fakes.create_fake_host()
        fake_host.failover_segment = fakes.create_fake_failover_segment(
            recovery_method='reserved_host')
        mock_host_obj.return_value = fake_host

        notification = self._get_compute_host_type_notification()

        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("error", notification.status)
コード例 #24
0
ファイル: test_engine_mgr.py プロジェクト: thaihust/masakari
    def test_process_notification_host_failure_without_reserved_hosts(
            self, mock_notification_save, mock_get_all, mock_host_update,
            mock_host_save, mock_host_obj):
        reserved_host_list = []
        mock_get_all.return_value = reserved_host_list

        fake_host = fakes.create_fake_host()
        fake_host.failover_segment = fakes.create_fake_failover_segment(
            recovery_method='reserved_host')
        mock_host_obj.return_value = fake_host

        notification = self._get_compute_host_type_notification()

        self.engine.process_notification(self.context,
                                         notification=notification)

        update_data_by_host_failure = {
            'on_maintenance': True,
        }
        mock_host_update.assert_called_once_with(update_data_by_host_failure)
        self.assertEqual("error", notification.status)
コード例 #25
0
ファイル: test_api.py プロジェクト: rkmrHonjo/masakari
 def setUp(self, mock_rpc):
     super(NotificationAPITestCase, self).setUp()
     self.notification_api = ha_api.NotificationAPI()
     self.req = fakes.HTTPRequest.blank('/v1/notifications',
                                        use_admin_context=True)
     self.context = self.req.environ['masakari.context']
     self.host = fakes_data.create_fake_host(
         name="host_1", id=1, reserved=False, on_maintenance=False,
         type="fake", control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1,
         failover_segment_id=uuidsentinel.fake_segment1
     )
     self.notification = fakes_data.create_fake_notification(
         type="VM", id=1, payload={
             'event': 'STOPPED', 'host_status': 'NORMAL',
             'cluster_status': 'ONLINE'
         },
         source_host_uuid=uuidsentinel.fake_host, generated_time=NOW,
         status="running",
         notification_uuid=uuidsentinel.fake_notification
     )
コード例 #26
0
ファイル: test_api.py プロジェクト: takanattie/masakari
    def test_get_all(self, mock_get, mock_get_all):
        mock_get.return_value = self.failover_segment
        fake_host = fakes_data.create_fake_host(
            name="host_2",
            id=2,
            reserved=False,
            on_maintenance=False,
            type="fake",
            control_attributes="fake-control_attributes",
            uuid=uuidsentinel.fake_host_2)
        fake_host_list = [self.host, fake_host]
        mock_get_all.return_value = fake_host_list

        result = self.host_api.get_all(self.context,
                                       filters=None,
                                       sort_keys=['created_at'],
                                       sort_dirs=['desc'],
                                       limit=None,
                                       marker=None)
        for i in range(len(result)):
            self._assert_host_data(fake_host_list[i],
                                   _make_host_obj(result[i]))
コード例 #27
0
 def setUp(self):
     super(HostAPITestCase, self).setUp()
     self.host_api = ha_api.HostAPI()
     self.req = fakes.HTTPRequest.blank('/v1/segments/%s/hosts' %
                                        uuidsentinel.fake_segment,
                                        use_admin_context=True)
     self.context = self.req.environ['masakari.context']
     self.failover_segment = fakes_data.create_fake_failover_segment(
         name="segment1",
         id=1,
         description="something",
         service_type="COMPUTE",
         recovery_method="auto",
         uuid=uuidsentinel.fake_segment)
     self.host = fakes_data.create_fake_host(
         name="host_1",
         id=1,
         reserved=False,
         on_maintenance=False,
         type="fake",
         control_attributes="fake-control_attributes",
         uuid=uuidsentinel.fake_host_1,
         failover_segment_id=uuidsentinel.fake_segment1)
コード例 #28
0
    def test_host_failure_flow_for_RH_recovery(self, _mock_notify,
                                               _mock_novaclient, mock_unlock,
                                               mock_lock, mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        self.override_config("evacuate_all_instances", True, "host_failure")
        self.override_config("add_reserved_host_to_aggregate", True,
                             "host_failure")

        # create test data
        self.fake_client.servers.create(id="1",
                                        host=self.instance_host,
                                        ha_enabled=True)
        self.fake_client.servers.create(id="2", host=self.instance_host)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(id="1",
                                           name='fake_agg',
                                           hosts=[self.instance_host])

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list(2)

        # execute EvacuateInstancesTask
        with mock.patch.object(manager, "update_host_method") as mock_save:
            self._evacuate_instances(instance_list,
                                     mock_enable_disable,
                                     reserved_host=reserved_host.name)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call("Disabling compute service on host: 'fake-host'"),
            mock.call("Disabled compute service on host: 'fake-host'", 1.0),
            mock.call('Preparing instances for evacuation'),
            mock.call(
                "Total instances running on failed host 'fake-host' is 2"
                "", 0.3),
            mock.call("Total HA Enabled instances count: '1'", 0.6),
            mock.call("Total Non-HA Enabled instances count: '1'", 0.7),
            mock.call(
                "All instances (HA Enabled/Non-HA Enabled) should be "
                "considered for evacuation. Total count is: '2'", 0.8),
            mock.call("Instances to be evacuated are: '1,2'", 1.0),
            mock.call("Start evacuation of instances from failed host "
                      "'fake-host', instance uuids are: '1,2'"),
            mock.call("Enabling reserved host: 'fake-reserved-host'", 0.1),
            mock.call('Add host fake-reserved-host to aggregate fake_agg',
                      0.2),
            mock.call('Added host fake-reserved-host to aggregate fake_agg',
                      0.3),
            mock.call("Evacuation of instance started: '1'", 0.5),
            mock.call("Evacuation of instance started: '2'", 0.5),
            mock.call(
                "Successfully evacuate instances '1,2' from host "
                "'fake-host'", 0.7),
            mock.call('Evacuation process completed!', 1.0)
        ])
コード例 #29
0
    def test_host_failure_flow_ignores_conflict_error(
            self, mock_log, _mock_notify, _mock_novaclient, mock_add_host,
            mock_unlock, mock_lock, mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        mock_add_host.side_effect = exception.Conflict
        self.override_config("add_reserved_host_to_aggregate", True,
                             "host_failure")

        # create test data
        self.fake_client.servers.create(id="1",
                                        host=self.instance_host,
                                        ha_enabled=True)
        reserved_host = fakes.create_fake_host(name="fake-reserved-host",
                                               reserved=True)
        self.fake_client.aggregates.create(
            id="1",
            name='fake_agg',
            hosts=[self.instance_host, reserved_host.name])
        expected_msg_format = ("Host '%(reserved_host)s' already has been "
                               "added to aggregate '%(aggregate)s'.") % {
                                   'reserved_host': 'fake-reserved-host',
                                   'aggregate': 'fake_agg'
                               }

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list(1)

        # execute EvacuateInstancesTask
        with mock.patch.object(manager, "update_host_method") as mock_save:
            self._evacuate_instances(instance_list,
                                     mock_enable_disable,
                                     reserved_host=reserved_host.name)
            self.assertEqual(1, mock_save.call_count)
            self.assertIn(reserved_host.name,
                          self.fake_client.aggregates.get('1').hosts)
            mock_log.info.assert_any_call(expected_msg_format)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call("Disabling compute service on host: 'fake-host'"),
            mock.call("Disabled compute service on host: 'fake-host'", 1.0),
            mock.call('Preparing instances for evacuation'),
            mock.call(
                "Total instances running on failed host 'fake-host' is 1"
                "", 0.3),
            mock.call("Total HA Enabled instances count: '1'", 0.6),
            mock.call("Instances to be evacuated are: '1'", 1.0),
            mock.call("Start evacuation of instances from failed host "
                      "'fake-host', instance uuids are: '1'"),
            mock.call("Enabling reserved host: 'fake-reserved-host'", 0.1),
            mock.call('Add host fake-reserved-host to aggregate fake_agg',
                      0.2),
            mock.call(
                "Host 'fake-reserved-host' already has been added to "
                "aggregate 'fake_agg'.", 1.0),
            mock.call("Evacuation of instance started: '1'", 0.5),
            mock.call(
                "Successfully evacuate instances '1' from host "
                "'fake-host'", 0.7),
            mock.call('Evacuation process completed!', 1.0)
        ])