Beispiel #1
0
 def RunSubTest(self, short_name, version, **kwargs):
     policy = copy.deepcopy(GOOD_POLICY)
     os_type = agent_policy.OpsAgentPolicy.Assignment.OsType(
         agent_policy.OpsAgentPolicy.Assignment.OsType.OsShortName(
             short_name), version)
     policy.assignment.os_types = [os_type]
     return validator.ValidateOpsAgentsPolicy(policy)
    def Run(self, args):
        """See base class."""

        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(
            release_track, api_version_override='v1beta')
        messages = osconfig_api_utils.GetClientMessages(
            release_track, api_version_override='v1beta')
        ops_agents_policy = agent_policy.CreateOpsAgentPolicy(
            args.description, args.agent_rules, args.group_labels,
            args.os_types, args.zones, args.instances)
        validator.ValidateOpsAgentsPolicy(ops_agents_policy)
        guest_policy = to_guest_policy.ConvertOpsAgentPolicyToGuestPolicy(
            messages, ops_agents_policy)
        project = properties.VALUES.core.project.GetOrFail()
        parent_path = osconfig_command_utils.GetProjectUriPath(project)
        request = messages.OsconfigProjectsGuestPoliciesCreateRequest(
            guestPolicy=guest_policy,
            guestPolicyId=args.POLICY_ID,
            parent=parent_path,
        )
        service = client.projects_guestPolicies
        complete_guest_policy = service.Create(request)
        ops_agents_policy = to_ops_agents.ConvertGuestPolicyToOpsAgentPolicy(
            complete_guest_policy)
        return ops_agents_policy
Beispiel #3
0
 def RunSubTest(self, version, enable_autoupgrade, **kwargs):
     agent_rule = copy.deepcopy(GOOD_METRICS_AGENT_RULE)
     agent_rule.version = version
     agent_rule.enable_autoupgrade = enable_autoupgrade
     policy = copy.deepcopy(GOOD_POLICY)
     policy.agent_rules = [agent_rule]
     return validator.ValidateOpsAgentsPolicy(policy)
Beispiel #4
0
 def RunSubTest(self, agent_type, version, **kwargs):
     agent_rule = copy.deepcopy(GOOD_LOGGING_AGENT_RULE)
     agent_rule.version = version
     agent_rule.type = agent_type
     agent_rule.enable_autoupgrade = False
     policy = copy.deepcopy(GOOD_POLICY)
     policy.agent_rules = [agent_rule]
     return validator.ValidateOpsAgentsPolicy(policy)
Beispiel #5
0
    def Run(self, args):
        """See base class."""
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(
            release_track, api_version_override='v1beta')
        messages = osconfig_api_utils.GetClientMessages(
            release_track, api_version_override='v1beta')

        project = properties.VALUES.core.project.GetOrFail()
        request = messages.OsconfigProjectsGuestPoliciesGetRequest(
            name=osconfig_command_utils.GetGuestPolicyUriPath(
                'projects', project, args.POLICY_ID))
        service = client.projects_guestPolicies
        current_guest_policy = service.Get(request)
        current_ops_agents_policy = guest_policy_to_ops_agents_policy_converter.ConvertGuestPolicyToOpsAgentPolicy(
            current_guest_policy)
        updated_ops_agents_policy = ops_agents_policy.UpdateOpsAgentsPolicy(
            current_ops_agents_policy, args.description, args.etag,
            args.agent_rules, args.os_types,
            [] if args.clear_group_labels else args.group_labels,
            [] if args.clear_zones else args.zones,
            [] if args.clear_instances else args.instances)
        ops_agents_policy_validator.ValidateOpsAgentsPolicy(
            updated_ops_agents_policy)
        updated_os_config_policy = ops_agents_policy_to_guest_policy_converter.ConvertOpsAgentPolicyToGuestPolicy(
            messages, updated_ops_agents_policy, current_guest_policy.recipes)
        request = messages.OsconfigProjectsGuestPoliciesPatchRequest(
            guestPolicy=updated_os_config_policy,
            name=osconfig_command_utils.GetGuestPolicyUriPath(
                'projects', project, args.POLICY_ID),
            updateMask=None,
        )
        complete_os_config_policy = service.Patch(request)
        complete_ops_agent_policy = guest_policy_to_ops_agents_policy_converter.ConvertGuestPolicyToOpsAgentPolicy(
            complete_os_config_policy)
        return complete_ops_agent_policy
Beispiel #6
0
 def RunSubTest(self, agent_rules, **kwargs):
     policy = copy.deepcopy(GOOD_POLICY)
     policy.agent_rules = agent_rules
     return validator.ValidateOpsAgentsPolicy(policy)
Beispiel #7
0
 def RunSubTest(self, os_types, **kwargs):
     policy = copy.deepcopy(GOOD_POLICY)
     policy.assignment.os_types = os_types
     return validator.ValidateOpsAgentsPolicy(policy)