Repository: RedHatInsights/insights-core

Issue:
Dependencies 'is_aws'/'is_azure' doesn't work on non-aws/non-azure system
The `insights.specs.default.DefaultSpecs.aws_instance_type` parser got the following result incorrectly from non-aws system:

```
# cat /tmp/insights-xxx-20200216034411/insights_commands/python_-m_insights.tools.cat_--no-header_aws_instance_type
Missing Dependencies:
    At Least One Of:
        insights.specs.default.DefaultSpecs.aws_instance_type
        insights.specs.insights_archive.InsightsArchiveSpecs.aws_instance_type
```
Then the `insights.parsers.aws_instance_type.AWSInstanceType` parser returns `.type` as "INSIGHTS", for all non-aws systems, which result some rules got fired incorrectly.

In fact, this spec `aws_instance_type` shouldn't be collected at all since it depends on `is_aws`:
https://github.com/RedHatInsights/insights-core/blob/0db5e8900507a6a60b58ac458a11644a8871306a/insights/specs/default.py#L100-L109

And the `is_aws` is skipped correctly:
```
# insights-cat insights.specs.default.DefaultSpecs.is_aws /tmp/insights-xxx-20200216034411
[Empty output]
```

And the dependency check works well:
```
# insights-cat insights.specs.default.DefaultSpecs.aws_instance_type /tmp/insights-xxx-20200216034411 
Missing Dependencies:
    Requires:
        insights.core.context.HostContext
        insights.specs.default.DefaultSpecs.is_aws
```
However, the spec is still collected by the client.
```
# cat /tmp/insights-xxx-20200216034411/insights_commands/python_-m_insights.tools.cat_--no-header_aws_instance_type
Missing Dependencies:
    At Least One Of:
        insights.specs.default.DefaultSpecs.aws_instance_type
        insights.specs.insights_archive.InsightsArchiveSpecs.aws_instance_type
```

It shouldn't be collected, right?

BTW, the `azure_*` and the other `aws_*` specs are also affected by this issue.





Discussion:
If we only call [dump_error](https://github.com/RedHatInsights/insights-core/blob/master/insights/tools/cat.py#L153-L160) when the debug option is passed, it should cause the command to not produce any output, and that should be enough [to prevent the client from putting a file in the archive](https://github.com/RedHatInsights/insights-core/blob/master/insights/client/archive.py#L172).

Resolving patch:
diff --git a/insights/client/archive.py b/insights/client/archive.py
--- a/insights/client/archive.py
+++ b/insights/client/archive.py
@@ -163,13 +163,16 @@ def add_to_archive(self, spec):
         Add files and commands to archive
         Use InsightsSpec.get_output() to get data
         '''
-        cmd_not_found_regex = "^timeout: failed to run command .+: No such file or directory$"
+        ab_regex = [
+            "^timeout: failed to run command .+: No such file or directory$",
+            "^Missing Dependencies:"
+        ]
         if isinstance(spec, InsightsCommand):
             archive_path = os.path.join(self.cmd_dir, spec.archive_path.lstrip('/'))
         if isinstance(spec, InsightsFile):
             archive_path = self.get_full_archive_path(spec.archive_path.lstrip('/'))
         output = spec.get_output()
-        if output and not re.search(cmd_not_found_regex, output):
+        if output and not any(re.search(rg, output) for rg in ab_regex):
             write_data_to_file(output, archive_path)
 
     def add_metadata_to_archive(self, metadata, meta_path):


Test patch:
diff --git a/insights/tests/client/test_skip_commands_files.py b/insights/tests/client/test_skip_commands_files.py
--- a/insights/tests/client/test_skip_commands_files.py
+++ b/insights/tests/client/test_skip_commands_files.py
@@ -99,6 +99,21 @@ def test_dont_archive_when_command_not_found(write_data_to_file):
     write_data_to_file.assert_called_once()
 
 
+@patch("insights.client.archive.write_data_to_file")
+def test_dont_archive_when_missing_dep(write_data_to_file):
+    """
+    If missing dependencies do not archive it
+    """
+    arch = InsightsArchive(InsightsConfig())
+
+    cmd = MagicMock(spec=InsightsCommand)
+    cmd.get_output.return_value = "Missing Dependencies:"
+    cmd.archive_path = '/path/to/command'
+
+    arch.add_to_archive(cmd)
+    write_data_to_file.assert_not_called()
+
+
 @patch("insights.client.data_collector.DataCollector._run_pre_command", return_value=['eth0'])
 @patch("insights.client.data_collector.InsightsCommand")
 def test_omit_after_parse_command(InsightsCommand, run_pre_command):