Пример #1
0
 def test_validate_uses_process(self, mock_validation_process_init,
                                mock_proj_journal_init):
     project_sim = self.simlab.simulate_assembly_basic()
     project = Project(project_sim.path)
     mock_consumer = mock.MagicMock()
     options = ValidateOptions()
     options.journal_consumer = mock_consumer
     result = project.validate(options)
     mock_proj_journal_init.assert_called_once_with(mock_consumer)
     mock_proj_journal = mock_proj_journal_init.return_value
     mock_validation_process_init.assert_called_once_with(
         project, options, mock_proj_journal)
     mock_validation_process = mock_validation_process_init.return_value
     mock_validation_process.execute.assert_called_once()
     self.assertEqual(result, mock_validation_process.execute.return_value)
Пример #2
0
 def test_validate_allow_autocorrect_moves_infrastructure_templates_to_lifecycle(
         self):
     project_sim = self.simlab.simulate_brent_with_infrastructure_templates(
     )
     project = Project(project_sim.path)
     find_yaml_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                   BRENT_INFRASTRUCTURE_DIR, 'find.yaml')
     with open(find_yaml_path, 'r') as f:
         find_yaml_content = f.read()
     heat_yaml_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                   BRENT_INFRASTRUCTURE_DIR,
                                   'openstack.yaml')
     with open(heat_yaml_path, 'r') as f:
         heat_yaml_content = f.read()
     kube_yaml_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                   BRENT_INFRASTRUCTURE_DIR, 'kube.yaml')
     with open(kube_yaml_path, 'r') as f:
         kube_yaml_content = f.read()
     validate_options = ValidateOptions()
     validate_options.allow_autocorrect = True
     result = project.validate(validate_options)
     self.assertFalse(result.has_errors())
     self.assertFalse(result.has_warnings())
     project = Project(project_sim.path)
     tester = self.assert_project(project)
     inf_manifest_path = os.path.join(project_sim.path,
                                      BRENT_DEFINITIONS_DIR,
                                      BRENT_INFRASTRUCTURE_DIR,
                                      BRENT_INFRASTRUCTURE_MANIFEST_FILE)
     tester.assert_has_no_file(find_yaml_path)
     tester.assert_has_no_file(heat_yaml_path)
     tester.assert_has_no_file(kube_yaml_path)
     tester.assert_has_file(
         os.path.join(project_sim.path, BRENT_LIFECYCLE_DIR,
                      BRENT_OPENSTACK_DIR, BRENT_OPENSTACK_HEAT_YAML_FILE),
         heat_yaml_content)
     tester.assert_has_file(
         os.path.join(project_sim.path, BRENT_LIFECYCLE_DIR,
                      BRENT_OPENSTACK_DIR,
                      BRENT_OPENSTACK_DISCOVER_YAML_FILE),
         find_yaml_content)
     tester.assert_has_file(
         os.path.join(project_sim.path, BRENT_LIFECYCLE_DIR,
                      BRENT_KUBERNETES_DIR, 'kube.yaml'), kube_yaml_content)
     lm_dir = os.path.join(BRENT_DEFINITIONS_DIR, BRENT_DESCRIPTOR_DIR)
     descriptor_path = os.path.join(lm_dir, BRENT_DESCRIPTOR_YML_FILE)
     tester.assert_has_file(descriptor_path,
                            EXPECTED_AUTOCORRECT_INFRASTRUCTURE_DESCRIPTOR)
Пример #3
0
 def test_validate_assembly_with_non_json_test(self):
     project_sim = self.simlab.simulate_invalid_assembly_non_json_test()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     test_path = os.path.join(project_sim.path, ASSEMBLY_BEHAVIOUR_DIR, ASSEMBLY_TESTS_DIR, 'notjson.xml')
     self.assert_validation_errors(result, 'Test [{0}]: is not a json file (with a .json extension)'.format(test_path))
Пример #4
0
 def test_validate_assembly_subproject_with_non_json_test(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_assembly_non_json_test()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     test_path = os.path.join(project_sim.path, PROJECT_CONTAINS_DIR, project_lab.SUBPROJECT_NAME_INVALID_ASSEMBLY_NON_JSON_TEST, ASSEMBLY_BEHAVIOUR_DIR, ASSEMBLY_TESTS_DIR, 'notjson.xml')
     self.assert_validation_errors(result, 'Test [{0}]: is not a json file (with a .json extension)'.format(test_path))
Пример #5
0
 def test_validate_assembly_with_invalid_json_test(self):
     project_sim = self.simlab.simulate_invalid_assembly_invalid_json_test()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     test_path = os.path.join(project_sim.path, ASSEMBLY_BEHAVIOUR_DIR, ASSEMBLY_TESTS_DIR, 'notvalid.json')
     self.assert_validation_errors(result, 'Test [{0}]: does not contain valid JSON: Expecting value: line 1 column 1 (char 0)'.format(test_path))
Пример #6
0
 def test_validate_allow_autocorrect_adds_selector_to_driver_entries_in_descriptor(
         self):
     project_sim = self.simlab.simulate_brent_with_missing_driver_selector()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     validate_options.allow_autocorrect = True
     result = project.validate(validate_options)
     self.assertFalse(result.has_errors())
     self.assertFalse(result.has_warnings())
     project = Project(project_sim.path)
     tester = self.assert_project(project)
     lm_dir = os.path.join(BRENT_DEFINITIONS_DIR, BRENT_DESCRIPTOR_DIR)
     descriptor_path = os.path.join(lm_dir, BRENT_DESCRIPTOR_YML_FILE)
     tester.assert_has_file(
         descriptor_path,
         EXPECTED_AUTOCORRECT_WITH_MISSING_DRIVER_SELECTORS_DESCRIPTOR)
Пример #7
0
 def test_validate_assembly_subproject_without_descriptor_file(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_assembly_no_descriptor()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, PROJECT_CONTAINS_DIR, project_lab.SUBPROJECT_NAME_INVALID_ASSEMBLY_NO_DESCRIPTOR, ASSEMBLY_DESCRIPTOR_DIR, ASSEMBLY_DESCRIPTOR_YML_FILE)
     self.assert_validation_errors(result, 'No descriptor found at: {0}'.format(descriptor_path))
Пример #8
0
 def test_validate_assembly_without_descriptor_file(self):
     project_sim = self.simlab.simulate_invalid_assembly_no_descriptor()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, ASSEMBLY_DESCRIPTOR_DIR, ASSEMBLY_DESCRIPTOR_YML_FILE)
     self.assert_validation_errors(result, 'No descriptor found at: {0}'.format(descriptor_path))
Пример #9
0
 def test_validate_assembly_subproject_with_invalid_json_runtime(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_assembly_invalid_json_runtime()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     runtime_path = os.path.join(project_sim.path, PROJECT_CONTAINS_DIR, project_lab.SUBPROJECT_NAME_INVALID_ASSEMBLY_INVALID_JSON_RUNTIME,
                                 ASSEMBLY_BEHAVIOUR_DIR, ASSEMBLY_RUNTIME_DIR, 'notvalid.json')
     self.assert_validation_errors(result, 'Runtime [{0}]: does not contain valid JSON: Expecting value: line 1 column 1 (char 0)'.format(runtime_path))
Пример #10
0
 def test_validate_assembly(self):
     project_sim = self.simlab.simulate_assembly_basic()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     self.assertIsInstance(result, ValidationResult)
     self.assertFalse(result.has_errors())
     self.assertFalse(result.has_warnings())
Пример #11
0
 def test_validate_resource_without_lifecycle(self):
     project_sim = self.simlab.simulate_invalid_brent_2dot1_no_lifecycle()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     lifecycle_path = os.path.join(project_sim.path, BRENT_LIFECYCLE_DIR)
     self.assert_validation_errors(
         result,
         'No Lifecycle directory found at: {0}'.format(lifecycle_path))
Пример #12
0
 def test_validate_resource_without_descriptor(self):
     project_sim = self.simlab.simulate_invalid_arm_no_descriptor()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, ARM_DESCRIPTOR_DIR,
                                    'invalid_no_descriptor.yml')
     self.assert_validation_errors(
         result, 'No descriptor found at: {0}'.format(descriptor_path))
Пример #13
0
 def test_validate_resource_without_manifest(self):
     project_sim = self.simlab.simulate_invalid_arm_no_manifest()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     manifest_path = os.path.join(project_sim.path, ARM_METAINF_DIR,
                                  ARM_MANIFEST_FILE)
     self.assert_validation_errors(
         result, 'No manifest found at: {0}'.format(manifest_path))
Пример #14
0
 def test_validate_resource_without_definitions(self):
     project_sim = self.simlab.simulate_invalid_brent_2dot1_no_definitions()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                    BRENT_DESCRIPTOR_DIR,
                                    BRENT_DESCRIPTOR_YML_FILE)
     self.assert_validation_errors(
         result, 'No descriptor found at: {0}'.format(descriptor_path))
Пример #15
0
 def test_validate_assembly_descriptor_template_name(self):
     project_sim = self.simlab.simulate_invalid_assembly_mismatch_descriptor_template_name()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, ASSEMBLY_DESCRIPTOR_DIR, 'assembly-template.yml')
     expected_errors = []
     expected_errors.append('Descriptor [{0}]: name \'resource::notvalid::9.7\' includes type \'resource\' but this should be \'assembly-template\' based on project configuration'.format(descriptor_path))
     expected_errors.append(
         'Descriptor [{0}]: name \'resource::notvalid::9.7\' includes \'notvalid\' but this should be \'invalid_mismatch_descriptor_template_name\' based on project configuration'.format(descriptor_path))
     expected_errors.append('Descriptor [{0}]: name \'resource::notvalid::9.7\' includes version \'9.7\' but this should be \'1.0\' based on project configuration'.format(descriptor_path))
     self.assert_validation_errors(result, *expected_errors)
Пример #16
0
 def test_validate_resource_without_lifecycle(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_brent_no_lifecycle(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     inf_path = os.path.join(
         project_sim.path, PROJECT_CONTAINS_DIR,
         project_lab.SUBPROJECT_NAME_INVALID_BRENT_NO_LIFECYCLE,
         BRENT_LIFECYCLE_DIR)
     self.assert_validation_errors(
         result, 'No Lifecycle directory found at: {0}'.format(inf_path))
Пример #17
0
 def test_validate_subproject_without_manifest(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_arm_no_manifest(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     manifest_path = os.path.join(
         project_sim.path, PROJECT_CONTAINS_DIR,
         project_lab.SUBPROJECT_NAME_INVALID_ARM_NO_MANIFEST,
         ARM_METAINF_DIR, ARM_MANIFEST_FILE)
     self.assert_validation_errors(
         result, 'No manifest found at: {0}'.format(manifest_path))
Пример #18
0
 def test_validate_assembly_subproject_descriptor_name(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_assembly_mismatch_descriptor_name()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, PROJECT_CONTAINS_DIR, project_lab.SUBPROJECT_NAME_INVALID_ASSEMBLY_MISMATCH_DESCRIPTOR_NAME, ASSEMBLY_DESCRIPTOR_DIR, 'assembly.yml')
     expected_errors = []
     expected_errors.append('Descriptor [{0}]: name \'resource::notvalid::9.7\' includes type \'resource\' but this should be \'assembly\' based on project configuration'.format(descriptor_path))
     expected_errors.append(
         'Descriptor [{0}]: name \'resource::notvalid::9.7\' includes \'notvalid\' but this should be \'sub_invalid_mismatch_descriptor_name-contains_invalid_mismatch_descriptor_name\' based on project configuration'.format(descriptor_path))
     expected_errors.append('Descriptor [{0}]: name \'resource::notvalid::9.7\' includes version \'9.7\' but this should be \'1.0\' based on project configuration'.format(descriptor_path))
     self.assert_validation_errors(result, *expected_errors)
Пример #19
0
 def test_validate_resource_without_infrastructure(self):
     project_sim = self.simlab.simulate_invalid_brent_2dot1_no_infrastructure(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     inf_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                             BRENT_INFRASTRUCTURE_DIR)
     self.assert_validation_errors(
         result,
         'No Infrastructure definitions directory found at: {0}'.format(
             inf_path))
Пример #20
0
 def test_validate_errors_on_driver_entries_missing_selector_in_descriptor(
         self):
     project_sim = self.simlab.simulate_brent_with_missing_driver_selector()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                    BRENT_DESCRIPTOR_DIR,
                                    BRENT_DESCRIPTOR_YML_FILE)
     self.assert_validation_errors(
         result,
         'Found lifecycle/operation/default-driver entries missing \'selector\' key before \'infrastructure-type\' [{0}]: this format is no longer supported by the Brent Resource Manager. Move infrastructure-type information under the selector key or enable the autocorrect option'
         .format(descriptor_path))
Пример #21
0
 def test_validate_resource_without_lm_descriptor(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_brent_no_lm_descriptor(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(
         project_sim.path, PROJECT_CONTAINS_DIR,
         project_lab.SUBPROJECT_NAME_INVALID_BRENT_NO_DESCRIPTOR,
         BRENT_DEFINITIONS_DIR, BRENT_DESCRIPTOR_DIR,
         BRENT_DESCRIPTOR_YML_FILE)
     self.assert_validation_errors(
         result, 'No descriptor found at: {0}'.format(descriptor_path))
Пример #22
0
 def test_validate_errors_on_infrastructure_templates(self):
     project_sim = self.simlab.simulate_brent_with_infrastructure_templates(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                    BRENT_DESCRIPTOR_DIR,
                                    BRENT_DESCRIPTOR_YML_FILE)
     self.assert_validation_errors(
         result,
         'Found infrastructure entries referencing templates [{0}]: this format is no longer supported by the Brent Resource Manager. Add this information to the Create/Delete lifecycle and/or queries instead or enable the autocorrect option'
         .format(descriptor_path))
Пример #23
0
 def test_validate_subproject_without_lifecycle(self):
     project_sim = self.simlab.simulate_assembly_contains_invalid_arm_no_lifecycle(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     lifecycle_path = os.path.join(
         project_sim.path, PROJECT_CONTAINS_DIR,
         project_lab.SUBPROJECT_NAME_INVALID_ARM_NO_LIFECYCLE,
         ARM_LIFECYCLE_DIR)
     self.assert_validation_errors(
         result,
         'No lifecycle sources found at: {0}'.format(lifecycle_path))
Пример #24
0
 def test_validate_allow_autocorrect_fixes_manifests(self):
     project_sim = self.simlab.simulate_brent_2dot1_with_prealpha_style()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     validate_options.allow_autocorrect = True
     result = project.validate(validate_options)
     self.assertFalse(result.has_errors())
     self.assertFalse(result.has_warnings())
     project = Project(project_sim.path)
     tester = self.assert_project(project)
     inf_manifest_path = os.path.join(project_sim.path,
                                      BRENT_DEFINITIONS_DIR,
                                      BRENT_INFRASTRUCTURE_DIR,
                                      BRENT_INFRASTRUCTURE_MANIFEST_FILE)
     tester.assert_has_no_file(inf_manifest_path)
     lifeycle_manifest_path = os.path.join(project_sim.path,
                                           BRENT_LIFECYCLE_DIR,
                                           BRENT_LIFECYCLE_MANIFEST_FILE)
     tester.assert_has_no_file(lifeycle_manifest_path)
     lm_dir = os.path.join(BRENT_DEFINITIONS_DIR, BRENT_DESCRIPTOR_DIR)
     descriptor_path = os.path.join(lm_dir, BRENT_DESCRIPTOR_YML_FILE)
     tester.assert_has_file(descriptor_path,
                            EXPECTED_AUTOCORRECT_DESCRIPTOR)
Пример #25
0
 def test_validate_errors_on_manifests(self):
     project_sim = self.simlab.simulate_brent_2dot1_with_prealpha_style()
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     inf_manifest_path = os.path.join(project_sim.path,
                                      BRENT_DEFINITIONS_DIR,
                                      BRENT_INFRASTRUCTURE_DIR,
                                      BRENT_INFRASTRUCTURE_MANIFEST_FILE)
     lifeycle_manifest_path = os.path.join(project_sim.path,
                                           BRENT_LIFECYCLE_DIR,
                                           BRENT_LIFECYCLE_MANIFEST_FILE)
     self.assert_validation_errors(
         result,
         'Found infrastructure manifest [{0}]: this file is no longer supported by the Brent Resource Manager. Add this information to the Resource descriptor instead or enable the autocorrect option'
         .format(inf_manifest_path),
         'Found lifecycle manifest [{0}]: this file is no longer supported by the Brent Resource Manager. Add this information to the Resource descriptor instead or enable the autocorrect option'
         .format(lifeycle_manifest_path))
Пример #26
0
 def test_validate_resource_descriptor_name(self):
     project_sim = self.simlab.simulate_invalid_brent_mismatch_descriptor_name(
     )
     project = Project(project_sim.path)
     validate_options = ValidateOptions()
     result = project.validate(validate_options)
     descriptor_path = os.path.join(project_sim.path, BRENT_DEFINITIONS_DIR,
                                    BRENT_DESCRIPTOR_DIR,
                                    BRENT_DESCRIPTOR_YML_FILE)
     expected_errors = []
     expected_errors.append(
         'Descriptor [{0}]: name \'assembly::notvalid::5.4\' includes type \'assembly\' but this should be \'resource\' based on project configuration'
         .format(descriptor_path))
     expected_errors.append(
         'Descriptor [{0}]: name \'assembly::notvalid::5.4\' includes \'notvalid\' but this should be \'invalid_mismatch_lm_descriptor_name\' based on project configuration'
         .format(descriptor_path))
     expected_errors.append(
         'Descriptor [{0}]: name \'assembly::notvalid::5.4\' includes version \'5.4\' but this should be \'1.0\' based on project configuration'
         .format(descriptor_path))
     self.assert_validation_errors(result, *expected_errors)
Пример #27
0
 def test_has_journal_consumer(self):
     self.assertTrue(hasattr(Options(), 'journal_consumer'))
     self.assertTrue(hasattr(ValidateOptions(), 'journal_consumer'))
     self.assertTrue(hasattr(BuildOptions(), 'journal_consumer'))
     self.assertTrue(hasattr(PullOptions(), 'journal_consumer'))