示例#1
0
    def test_unload_policy_file_with_bad_schema(self, os_unlink, _1, _2, _3,
                                                _4, _5):
        host = Host(DEFAULT_EVENT_QUEUE_ID, DEFAULT_EVENT_QUEUE_NAME,
                    DEFAULT_POLICY_STORAGE)

        # Schedule is invalid
        policy_string = """
                            policie:
                              - name: foo
                                mode:
                                  type: container-periodic
                                  schedule: '* * * *'
                                resource: azure.resourcegroup
                        """

        # Create a bad yaml file
        file_path = tempfile.mktemp(suffix=".yaml")
        with open(file_path, 'w') as f:
            f.write(policy_string)

        host.load_policy(file_path, host.policies)
        host.unload_policy_file(file_path, host.policies)
        os_unlink.assert_called()

        # Clean up the file
        os.remove(file_path)
示例#2
0
    def test_unload_policy_file_with_yaml_error(self, os_unlink,
                                                yaml_safe_load, _1, _2, _3, _4,
                                                _5):
        host = Host(DEFAULT_EVENT_QUEUE_ID, DEFAULT_EVENT_QUEUE_NAME,
                    DEFAULT_POLICY_STORAGE)

        # Create a bad yaml file
        file_path = tempfile.mktemp(suffix=".yaml")
        with open(file_path, 'w') as f:
            f.write("bad yaml file")

        host.load_policy(file_path, host.policies)
        host.unload_policy_file(file_path, host.policies)
        os_unlink.assert_called()

        # Clean up the file
        os.remove(file_path)
示例#3
0
    def test_unload_policy_file_without_name(self, os_unlink, yaml_safe_load,
                                             _1, _2, _3, _4):
        host = Host(DEFAULT_EVENT_QUEUE_ID, DEFAULT_EVENT_QUEUE_NAME,
                    DEFAULT_POLICY_STORAGE)

        # Create a bad yaml file (no name field)
        file_path = tempfile.mktemp(suffix=".yaml")
        with open(file_path, 'w') as f:
            f.write("""
                        policies:
                          - mode:
                              type: container-periodic
                              schedule: '* * * * *'
                            resource: azure.resourcegroup
                        """)

        host.load_policy(file_path, host.policies)
        host.unload_policy_file(file_path, host.policies)
        os_unlink.assert_called()

        # Clean up the file
        os.remove(file_path)