コード例 #1
0
    def test_set_current_with_force(self, urlopen_mock, get_verbose_mock,
                                    get_ambari_server_api_base_mock,
                                    get_ambari_properties_mock,
                                    get_validated_string_input_mock,
                                    no_finalize_options_set_mock,
                                    is_server_runing_mock):
        options = MagicMock()
        options.cluster_name = 'cc'
        options.desired_repo_version = 'HDP-2.2.2.0-2561'
        options.force_repo_version = True

        # Case when server is not running
        is_server_runing_mock.return_value = False, None
        try:
            set_current(options)
            self.fail("Server is not running - should error out")
        except FatalException:
            pass  # expected

        is_server_runing_mock.return_value = True, 11111

        # Test insufficient options case
        no_finalize_options_set_mock.return_value = True
        try:
            set_current(options)
            self.fail("Should error out")
        except FatalException:
            pass  # expected

        no_finalize_options_set_mock.return_value = False

        # Test normal flow
        get_validated_string_input_mock.return_value = 'dummy_string'

        p = get_ambari_properties_mock.return_value
        p.get_property.side_effect = ["8080", "false"]

        get_ambari_server_api_base_mock.return_value = 'http://127.0.0.1:8080/api/v1/'
        get_verbose_mock.retun_value = False

        set_current(options)

        self.assertTrue(urlopen_mock.called)
        request = urlopen_mock.call_args_list[0][0][0]
        self.assertEquals(
            request._Request__original,
            'http://127.0.0.1:8080/api/v1/clusters/cc/stack_versions')
        self.assertEquals(
            request.data,
            '{"ClusterStackVersions": {"state": "CURRENT", "repository_version": "HDP-2.2.2.0-2561", "force": "true"}}'
        )
        self.assertEquals(request.origin_req_host, '127.0.0.1')
        self.assertEquals(
            request.headers, {
                'X-requested-by': 'ambari',
                'Authorization': 'Basic ZHVtbXlfc3RyaW5nOmR1bW15X3N0cmluZw=='
            })
コード例 #2
0
ファイル: TestServerUpgrade.py プロジェクト: biggeng/ambari
  def test_set_current_with_force(self, urlopen_mock, get_verbose_mock, get_ambari_server_api_base_mock,
                       get_ambari_properties_mock, get_validated_string_input_mock,
                       no_finalize_options_set_mock, is_server_runing_mock):
    options = MagicMock()
    options.cluster_name = 'cc'
    options.desired_repo_version = 'HDP-2.2.2.0-2561'
    options.force_repo_version = True

    # Case when server is not running
    is_server_runing_mock.return_value = False, None
    try:
      set_current(options)
      self.fail("Server is not running - should error out")
    except FatalException:
      pass  # expected


    is_server_runing_mock.return_value = True, 11111

    # Test insufficient options case
    no_finalize_options_set_mock.return_value = True
    try:
      set_current(options)
      self.fail("Should error out")
    except FatalException:
      pass  # expected

    no_finalize_options_set_mock.return_value = False

    # Test normal flow
    get_validated_string_input_mock.return_value = 'dummy_string'

    p = get_ambari_properties_mock.return_value
    p.get_property.side_effect = ["8080", "false"]

    get_ambari_server_api_base_mock.return_value = 'http://127.0.0.1:8080/api/v1/'
    get_verbose_mock.retun_value = False

    set_current(options)

    self.assertTrue(urlopen_mock.called)
    request = urlopen_mock.call_args_list[0][0][0]
    self.assertEquals(request._Request__original, 'http://127.0.0.1:8080/api/v1/clusters/cc/stack_versions')
    self.assertEquals(request.data, '{"ClusterStackVersions": {"state": "CURRENT", "repository_version": "HDP-2.2.2.0-2561", "force": "true"}}')
    self.assertEquals(request.origin_req_host, '127.0.0.1')
    self.assertEquals(request.headers, {'X-requested-by': 'ambari', 'Authorization': 'Basic ZHVtbXlfc3RyaW5nOmR1bW15X3N0cmluZw=='})