def test_poll_success(self, logger):
     poll_utils.poll(**{'get_status': lambda: True,
                        'kwargs': {}, 'timeout': 5, 'sleep': 3})
     expected_call = mock.call(
         'Operation was executed successfully in timeout 5')
     self.assertEqual(1, logger.call_count)
     self.assertEqual([expected_call], logger.call_args_list)
Beispiel #2
0
 def test_poll_success(self, logger):
     poll_utils.poll(**{
         'get_status': lambda: True,
         'kwargs': {},
         'timeout': 5,
         'sleep': 3
     })
     expected_call = mock.call(
         'Operation was executed successfully in timeout 5')
     self.assertEqual(1, logger.call_count)
     self.assertEqual([expected_call], logger.call_args_list)
Beispiel #3
0
def wait_host_registration(cluster):
    ambari = plugin_utils.get_instance(cluster, p_common.AMBARI_SERVER)
    hosts = plugin_utils.get_instances(cluster)
    password = cluster.extra["ambari_password"]
    with ambari_client.AmbariClient(ambari, password=password) as client:
        kwargs = {"client": client, "num_hosts": len(hosts)}
        poll_utils.poll(_check_host_registration, kwargs=kwargs, timeout=600)
        registered_hosts = client.get_registered_hosts()
    registered_host_names = [h["Hosts"]["host_name"] for h in registered_hosts]
    actual_host_names = [h.fqdn() for h in hosts]
    if sorted(registered_host_names) != sorted(actual_host_names):
        raise p_exc.HadoopProvisionError(
            _("Host registration fails in Ambari"))
Beispiel #4
0
def wait_host_registration(cluster):
    ambari = plugin_utils.get_instance(cluster, p_common.AMBARI_SERVER)
    hosts = plugin_utils.get_instances(cluster)
    password = cluster.extra["ambari_password"]
    with ambari_client.AmbariClient(ambari, password=password) as client:
        kwargs = {"client": client, "num_hosts": len(hosts)}
        poll_utils.poll(_check_host_registration, kwargs=kwargs, timeout=600)
        registered_hosts = client.get_registered_hosts()
    registered_host_names = [h["Hosts"]["host_name"] for h in registered_hosts]
    actual_host_names = [h.fqdn() for h in hosts]
    if sorted(registered_host_names) != sorted(actual_host_names):
        raise p_exc.HadoopProvisionError(
            _("Host registration fails in Ambari"))
    def test_poll_failed_first_scenario(self, p_1, p_2):
        message = ""
        try:
            poll_utils.poll(
                **{'get_status': lambda: False, 'kwargs': {},
                   'timeout': 0, 'sleep': 3})
        except Exception as e:
            message = six.text_type(e)

        if message.find('Error ID') != -1:
            message = message.split("\n")[0]
        expected_message = "'Operation' timed out after 0 second(s)"

        self.assertEqual(expected_message, message)
    def test_poll_failed_second_scenario(self, p_1, p_2):
        message = ""
        try:
            poll_utils.poll(
                **{'get_status': lambda: False, 'kwargs': {},
                   'timeout': 0, 'sleep': 3, 'timeout_name': "some timeout"})
        except Exception as e:
            message = six.text_type(e)

        if message.find('Error ID') != -1:
            message = message.split("\n")[0]
        expected_message = ("'Operation' timed out after 0 second(s) and "
                            "following timeout was violated: some timeout")

        self.assertEqual(expected_message, message)
Beispiel #7
0
def poll(get_status,
         kwargs=None,
         args=None,
         operation_name=None,
         timeout_name=None,
         timeout=poll_utils.DEFAULT_TIMEOUT,
         sleep=poll_utils.DEFAULT_SLEEP_TIME,
         exception_strategy='raise'):
    poll_utils.poll(get_status,
                    kwargs=kwargs,
                    args=args,
                    operation_name=operation_name,
                    timeout_name=timeout_name,
                    timeout=timeout,
                    sleep=sleep,
                    exception_strategy=exception_strategy)
Beispiel #8
0
    def test_poll_failed_first_scenario(self, p_1, p_2):
        message = ""
        try:
            poll_utils.poll(
                **{
                    'get_status': lambda: False,
                    'kwargs': {},
                    'timeout': 0,
                    'sleep': 3
                })
        except Exception as e:
            message = six.text_type(e)

        if message.find('Error ID') != -1:
            message = message.split("\n")[0]
        expected_message = "'Operation' timed out after 0 second(s)"

        self.assertEqual(expected_message, message)
Beispiel #9
0
    def test_poll_failed_second_scenario(self, p_1, p_2):
        message = ""
        try:
            poll_utils.poll(
                **{
                    'get_status': lambda: False,
                    'kwargs': {},
                    'timeout': 0,
                    'sleep': 3,
                    'timeout_name': "some timeout"
                })
        except Exception as e:
            message = six.text_type(e)

        if message.find('Error ID') != -1:
            message = message.split("\n")[0]
        expected_message = ("'Operation' timed out after 0 second(s) and "
                            "following timeout was violated: some timeout")

        self.assertEqual(expected_message, message)
Beispiel #10
0
 def poll_status(instance):
     operation_name = _('Wait for {node_process} on {instance}'
                        ' to change status to "{status}"')
     args = {
         'node_process': self.ui_name,
         'instance': instance.instance_name,
         'status': status.name,
     }
     return polls.poll(
         get_status=lambda: self.status(instance) == status,
         operation_name=operation_name.format(**args),
         timeout=timeout,
         sleep=sleep,
     )
Beispiel #11
0
 def poll_status(instance):
     operation_name = _('Wait for {node_process} on {instance}'
                        ' to change status to "{status}"')
     args = {
         'node_process': self.ui_name,
         'instance': instance.instance_name,
         'status': status.name,
     }
     return polls.poll(
         get_status=lambda: self.status(instance) == status,
         operation_name=operation_name.format(**args),
         timeout=timeout,
         sleep=sleep,
     )
Beispiel #12
0
def wait_host_registration(cluster, instances):
    ambari = plugin_utils.get_instance(cluster, p_common.AMBARI_SERVER)
    password = cluster.extra["ambari_password"]
    with ambari_client.AmbariClient(ambari, password=password) as client:
        kwargs = {"client": client, "instances": instances}
        poll_utils.poll(_check_host_registration, kwargs=kwargs, timeout=600)
Beispiel #13
0
def wait_host_registration(cluster, instances):
    with _get_ambari_client(cluster) as client:
        kwargs = {"client": client, "instances": instances}
        poll_utils.poll(_check_host_registration, kwargs=kwargs, timeout=600)
Beispiel #14
0
def wait_ambari_accessible(cluster):
    ambari = plugin_utils.get_instance(cluster, p_common.AMBARI_SERVER)
    kwargs = {"host": ambari.management_ip, "port": 8080}
    poll_utils.poll(_check_port_accessible, kwargs=kwargs, timeout=300)
Beispiel #15
0
def wait_ambari_accessible(cluster):
    ambari = plugin_utils.get_instance(cluster, p_common.AMBARI_SERVER)
    kwargs = {"host": ambari.management_ip, "port": 8080}
    poll_utils.poll(_check_port_accessible, kwargs=kwargs, timeout=300)
Beispiel #16
0
def wait_host_registration(cluster, instances):
    with _get_ambari_client(cluster) as client:
        kwargs = {"client": client, "instances": instances}
        poll_utils.poll(_check_host_registration, kwargs=kwargs, timeout=600)
Beispiel #17
0
def wait_host_registration(cluster, instances):
    ambari = plugin_utils.get_instance(cluster, p_common.AMBARI_SERVER)
    password = cluster.extra["ambari_password"]
    with ambari_client.AmbariClient(ambari, password=password) as client:
        kwargs = {"client": client, "instances": instances}
        poll_utils.poll(_check_host_registration, kwargs=kwargs, timeout=600)
Beispiel #18
0
 def test_poll_exception_strategy_third_scenario(self):
     fake_get_status = mock.Mock()
     fake_get_status.side_effect = [False, ValueError(), True]
     poll_utils.poll(fake_get_status, exception_strategy='mark_as_false')
     self.assertEqual(3, fake_get_status.call_count)
 def test_poll_exception_strategy_third_scenario(self):
     fake_get_status = mock.Mock()
     fake_get_status.side_effect = [False, ValueError(), True]
     poll_utils.poll(fake_get_status, exception_strategy='mark_as_false')
     self.assertEqual(3, fake_get_status.call_count)
    def test_poll_exception_strategy_first_scenario(self):
        fake_get_status = mock.Mock()
        fake_get_status.side_effect = [False, ValueError()]

        with testtools.ExpectedException(ValueError):
            poll_utils.poll(fake_get_status)
Beispiel #21
0
    def test_poll_exception_strategy_first_scenario(self):
        fake_get_status = mock.Mock()
        fake_get_status.side_effect = [False, ValueError()]

        with testtools.ExpectedException(ValueError):
            poll_utils.poll(fake_get_status)