Example #1
0
    def test_requestComponentSecurityState(self, FileCache_mock,
                                           runCommand_mock):
        FileCache_mock.return_value = None
        status_command = {
            "serviceName": 'HDFS',
            "commandType": "STATUS_COMMAND",
            "clusterName": "",
            "componentName": "DATANODE",
            'configurations': {}
        }
        dummy_controller = MagicMock()
        orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
        # Test securityState
        runCommand_mock.return_value = {
            'exitcode': 0,
            'structuredOut': {
                'securityState': 'UNSECURED'
            }
        }

        status = orchestrator.requestComponentSecurityState(status_command)
        self.assertEqual('UNSECURED', status)

        # Test case where exit code indicates failure
        runCommand_mock.return_value = {"exitcode": 1}
        status = orchestrator.requestComponentSecurityState(status_command)
        self.assertEqual('UNKNOWN', status)
  def test_requestComponentSecurityState(self, FileCache_mock, runCommand_mock):
    FileCache_mock.return_value = None
    status_command = {
      "serviceName" : 'HDFS',
      "commandType" : "STATUS_COMMAND",
      "clusterName" : "",
      "componentName" : "DATANODE",
      'configurations':{}
    }
    dummy_controller = MagicMock()
    orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)
    # Test securityState
    runCommand_mock.return_value = {
      'exitcode' : 0,
      'structuredOut' : {'securityState': 'UNSECURED'}
    }

    status = orchestrator.requestComponentSecurityState(status_command)
    self.assertEqual('UNSECURED', status)

    # Test case where exit code indicates failure
    runCommand_mock.return_value = {
      "exitcode" : 1
    }
    status = orchestrator.requestComponentSecurityState(status_command)
    self.assertEqual('UNKNOWN', status)
Example #3
0
    def test_requestComponentSecurityState_realFailure(self, FileCache_mock):
        '''
    Tests the case where the CustomServiceOrchestrator attempts to call a service's security_status
    method, but fails to do so because the script or method was not found.
    :param FileCache_mock:
    :return:
    '''
        FileCache_mock.return_value = None
        status_command = {
            "serviceName": 'BOGUS_SERVICE',
            "commandType": "STATUS_COMMAND",
            "clusterName": "",
            "componentName": "DATANODE",
            'configurations': {}
        }
        dummy_controller = MagicMock()
        orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)

        status = orchestrator.requestComponentSecurityState(status_command)
        self.assertEqual('UNKNOWN', status)
  def test_requestComponentSecurityState_realFailure(self, FileCache_mock):
    '''
    Tests the case where the CustomServiceOrchestrator attempts to call a service's security_status
    method, but fails to do so because the script or method was not found.
    :param FileCache_mock:
    :return:
    '''
    FileCache_mock.return_value = None
    status_command = {
      "serviceName" : 'BOGUS_SERVICE',
      "commandType" : "STATUS_COMMAND",
      "clusterName" : "",
      "componentName" : "DATANODE",
      'configurations':{}
    }
    dummy_controller = MagicMock()
    orchestrator = CustomServiceOrchestrator(self.config, dummy_controller)

    status = orchestrator.requestComponentSecurityState(status_command)
    self.assertEqual('UNKNOWN', status)