Esempio n. 1
0
 def register_password_missing_test(self, get_proxy, thread_mgr_wait,
                                    run_task, switch_source):
     """Test the register_and_subscribe() helper method - password missing."""
     payload = Mock()
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.PASSWORD_MISSING_REQUEST
     # run the function
     register_and_subscribe(payload=payload,
                            progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # there should be only the registration phase
     progress_callback.assert_has_calls([call(SubscriptionPhase.REGISTER)])
     # and the error callback should have been triggered
     error_callback.assert_called_once()
     # in this case we fail before requesting any other task than
     # the config one
     subscription_proxy.SetRHSMConfigWithTask.assert_called_once()
     run_task.assert_called()
     # setting CDN as installation source does not make sense
     # when we were not able to attach a subscription
     switch_source.assert_not_called()
Esempio n. 2
0
 def register_username_password_test(self, get_proxy, thread_mgr_wait, run_task, set_cdn):
     """Test the register_and_subscribe() helper method - username & password."""
     payload = Mock()
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.PASSWORD_REQUEST
     # run the function
     register_and_subscribe(payload=payload,
                            progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # system was no registered, so no unregistration phase
     print(error_callback.mock_calls)
     progress_callback.assert_has_calls(
         [call(SubscriptionPhase.REGISTER),
          call(SubscriptionPhase.ATTACH_SUBSCRIPTION),
          call(SubscriptionPhase.DONE)]
     )
     # we were successful, so no error callback calls
     error_callback.assert_not_called()
     # we should have requested the appropriate tasks
     subscription_proxy.SetRHSMConfigWithTask.assert_called_once()
     subscription_proxy.RegisterUsernamePasswordWithTask.assert_called_once()
     subscription_proxy.AttachSubscriptionWithTask.assert_called_once()
     subscription_proxy.ParseAttachedSubscriptionsWithTask.assert_called_once()
     # tried to set the CDN source
     set_cdn.assert_called_once()
     # and tried to run them
     run_task.assert_called()
Esempio n. 3
0
 def register_username_password_task_failed_test(self, get_proxy,
                                                 thread_mgr_wait, run_task,
                                                 switch_source):
     """Test the register_and_subscribe() helper method - username & password failed."""
     payload = Mock()
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.PASSWORD_REQUEST
     # make the first (registration) task fail
     run_task.side_effect = [True, RegistrationError("registration failed")]
     # run the function
     register_and_subscribe(payload=payload,
                            progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # there should be only the registration phase
     progress_callback.assert_has_calls([call(SubscriptionPhase.REGISTER)])
     # and the error callback should have been triggered
     error_callback.assert_called_once_with("registration failed")
     # we should have requested the appropriate tasks
     subscription_proxy.SetRHSMConfigWithTask.assert_called_once()
     subscription_proxy.RegisterUsernamePasswordWithTask.assert_called_once(
     )
     # and tried to run them
     run_task.assert_called()
     # setting CDN as installation source does not make sense
     # when we were not able to attach a subscription
     switch_source.assert_not_called()
Esempio n. 4
0
 def attach_subscription_task_failed_test(self, get_proxy, thread_mgr_wait,
                                          run_task):
     """Test the register_and_subscribe() helper method - failed to attach subscription."""
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.PASSWORD_REQUEST
     # make the second (subscription) task fail
     run_task.side_effect = [
         True, SubscriptionError("failed to attach subscription")
     ]
     # run the function
     register_and_subscribe(progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # there should be only the registration & subscription phase
     progress_callback.assert_has_calls([
         call(SubscriptionPhase.REGISTER),
         call(SubscriptionPhase.ATTACH_SUBSCRIPTION)
     ])
     # and the error callback should have been triggered
     error_callback.assert_called_once_with("failed to attach subscription")
     # we should have requested the appropriate tasks
     subscription_proxy.RegisterUsernamePasswordWithTask.assert_called_once(
     )
     subscription_proxy.AttachSubscriptionWithTask.assert_called_once()
     # and tried to run them
     run_task.assert_called()
Esempio n. 5
0
 def register_org_key_task_failed_test(self, get_proxy, thread_mgr_wait,
                                       run_task):
     """Test the register_and_subscribe() helper method - org & key failed."""
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.KEY_REQUEST
     # make the first (registration) task fail
     run_task.side_effect = [RegistrationError("registration failed")]
     # run the function
     register_and_subscribe(progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # there should be only the registration phase
     progress_callback.assert_has_calls([call(SubscriptionPhase.REGISTER)])
     # and the error callback should have been triggered
     error_callback.assert_called_once_with("registration failed")
     # we should have requested the appropriate tasks
     subscription_proxy.RegisterOrganizationKeyWithTask.assert_called_once()
     # and tried to run them
     run_task.assert_called()
Esempio n. 6
0
 def unregister_register_test(self, get_proxy, thread_mgr_wait, run_task):
     """Test the register_and_subscribe() helper method - registered system."""
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system being registered,
     # - this should add additional unregister phase and task
     subscription_proxy.IsRegistered = True
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.KEY_REQUEST
     # run the function
     register_and_subscribe(progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # check the phases and their order
     progress_callback.assert_has_calls([
         call(SubscriptionPhase.UNREGISTER),
         call(SubscriptionPhase.REGISTER),
         call(SubscriptionPhase.ATTACH_SUBSCRIPTION),
         call(SubscriptionPhase.DONE)
     ])
     # we were successful, so no error callback calls
     error_callback.assert_not_called()
     # we should have requested the appropriate tasks
     subscription_proxy.UnregisterWithTask.assert_called_once()
     subscription_proxy.RegisterOrganizationKeyWithTask.assert_called_once()
     subscription_proxy.AttachSubscriptionWithTask.assert_called_once()
     subscription_proxy.ParseAttachedSubscriptionsTask.assert_called_once()
     # and tried to run them
     run_task.assert_called()
Esempio n. 7
0
 def register_key_missing_test(self, get_proxy, thread_mgr_wait, run_task):
     """Test the register_and_subscribe() helper method - key missing."""
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.KEY_MISSING_REQUEST
     # run the function
     register_and_subscribe(progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # there should be only the registration phase
     progress_callback.assert_has_calls([call(SubscriptionPhase.REGISTER)])
     # and the error callback should have been triggered
     error_callback.assert_called_once()
     # int this case we fails before requesting any task and we should not
     # attempt to run any
     run_task.assert_not_called()
Esempio n. 8
0
 def register_override_cdrom_test(self, get_proxy, thread_mgr_wait,
                                  run_task, switch_source):
     """Test the register_and_subscribe() helper method - override CDROM source."""
     payload = Mock()
     payload.type = PAYLOAD_TYPE_DNF
     payload.data.repo.dataList = MagicMock(return_value=[])
     source_proxy = payload.get_source_proxy.return_value
     source_proxy.Type = SOURCE_TYPE_CDROM
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.KEY_REQUEST
     # run the function
     register_and_subscribe(payload=payload,
                            progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # system was no registered, so no unregistration phase
     progress_callback.assert_has_calls([
         call(SubscriptionPhase.REGISTER),
         call(SubscriptionPhase.ATTACH_SUBSCRIPTION),
         call(SubscriptionPhase.DONE)
     ])
     # we were successful, so no error callback calls
     error_callback.assert_not_called()
     # we should have requested the appropriate tasks
     subscription_proxy.SetRHSMConfigWithTask.assert_called_once()
     subscription_proxy.RegisterOrganizationKeyWithTask.assert_called_once()
     subscription_proxy.AttachSubscriptionWithTask.assert_called_once()
     subscription_proxy.ParseAttachedSubscriptionsWithTask.assert_called_once(
     )
     # and tried to override the CDROM source, as it is on a list of sources
     # that are appropriate to be overriden by the CDN source
     switch_source.assert_called_once_with(payload, SOURCE_TYPE_CDN)
     # and tried to run them
     run_task.assert_called()
Esempio n. 9
0
 def register_org_key_test(self, get_proxy, thread_mgr_wait, run_task,
                           switch_source):
     """Test the register_and_subscribe() helper method - org & key."""
     payload = Mock()
     source_proxy = payload.get_source_proxy.return_value
     source_proxy.Type = SOURCE_TYPE_CLOSEST_MIRROR
     progress_callback = Mock()
     error_callback = Mock()
     subscription_proxy = get_proxy.return_value
     # simulate the system not being registered
     subscription_proxy.IsRegistered = False
     # simulate subscription request
     subscription_proxy.SubscriptionRequest = self.KEY_REQUEST
     # run the function
     register_and_subscribe(payload=payload,
                            progress_callback=progress_callback,
                            error_callback=error_callback)
     # we should have waited on network
     thread_mgr_wait.assert_called_once_with(THREAD_WAIT_FOR_CONNECTING_NM)
     # system was no registered, so no unregistration phase
     progress_callback.assert_has_calls([
         call(SubscriptionPhase.REGISTER),
         call(SubscriptionPhase.ATTACH_SUBSCRIPTION),
         call(SubscriptionPhase.DONE)
     ])
     # we were successful, so no error callback calls
     error_callback.assert_not_called()
     # we should have requested the appropriate tasks
     subscription_proxy.SetRHSMConfigWithTask.assert_called_once()
     subscription_proxy.RegisterOrganizationKeyWithTask.assert_called_once()
     subscription_proxy.AttachSubscriptionWithTask.assert_called_once()
     subscription_proxy.ParseAttachedSubscriptionsWithTask.assert_called_once(
     )
     # not tried to set the CDN source
     switch_source.assert_not_called()
     # and tried to run them
     run_task.assert_called()