Ejemplo n.º 1
0
    def testListPoliciesFormat(self):
        properties.VALUES.core.user_output_enabled.Set(True)
        list_request = self.messages.DnsPoliciesListRequest(
            project=self.Project())
        test_networks = [
            util.GetNetworkURI('default', self.Project()),
            util.GetNetworkURI('network1', self.Project())
        ]
        name_servers = util.GetAltNameServerConfig(['2.0.1.1', '2.0.1.2'])
        expected_output = util.GetPolicies(name_server_config=name_servers,
                                           networks=test_networks,
                                           forwarding=True,
                                           logging=True)
        self.client.policies.List.Expect(
            request=list_request,
            response=self.messages.PoliciesListResponse(
                policies=expected_output))
        self.Run('dns policies list')
        self.AssertOutputContains("""\
NAME DESCRIPTION FORWARDING LOGGING ALTERNATE_NAME_SERVERS NETWORKS
mypolicy0 My policy 0 True True 2.0.1.1, 2.0.1.2 default, network1
mypolicy1 My policy 1 True True 2.0.1.1, 2.0.1.2 default, network1
mypolicy2 My policy 2 True True 2.0.1.1, 2.0.1.2 default, network1
""",
                                  normalize_space=True)
Ejemplo n.º 2
0
 def testDescribe(self):
     expected_output = util.GetPolicies(networks=[], num=1).pop()
     describe_req = self.messages.DnsPoliciesGetRequest(
         project=self.Project(), policy='mypolicy0')
     self.client.policies.Get.Expect(request=describe_req,
                                     response=expected_output)
     actual_output = self.Run('dns policies describe mypolicy0')
     self.assertEqual(expected_output, actual_output)
Ejemplo n.º 3
0
 def testCreateMinimalEmptyNetworks(self):
   expected_output = util.GetPolicies(networks=[], num=1).pop()
   create_req = self.messages.DnsPoliciesCreateRequest(
       project=self.Project(), policy=expected_output)
   self.client.policies.Create.Expect(
       request=create_req, response=expected_output)
   actual_output = self.Run('dns policies create mypolicy0 --description '
                            '"My policy 0" --networks=""')
   self.assertEqual(expected_output, actual_output)
Ejemplo n.º 4
0
 def testUpdateNone(self):
     expected_output = util.GetPolicies(networks=[], num=1).pop()
     get_req = self.messages.DnsPoliciesGetRequest(project=self.Project(),
                                                   policy='mypolicy0')
     self.client.policies.Get.Expect(request=get_req,
                                     response=expected_output)
     actual_output = self.Run('dns policies update mypolicy0')
     self.assertEqual(expected_output, actual_output)
     self.AssertErrContains('Nothing to update.')
Ejemplo n.º 5
0
 def testListPolicies(self):
     properties.VALUES.core.user_output_enabled.Set(False)
     expected_output = util.GetPolicies(networks=['1.0.1.1', '1.0.1.2'])
     list_request = self.messages.DnsPoliciesListRequest(
         project=self.Project())
     self.client.policies.List.Expect(
         request=list_request,
         response=self.messages.PoliciesListResponse(
             policies=expected_output))
     actual_output = self.Run('dns policies list')
     self.assertEqual(expected_output, actual_output)
Ejemplo n.º 6
0
    def _ExpectUpdate(self,
                      description=None,
                      name_servers=None,
                      private_name_servers=None,
                      networks=None,
                      forwarding=None,
                      logging=None):
        get_output = util.GetPolicies(networks=[], num=1).pop()
        expected_output = util.GetPolicies(networks=[], num=1).pop()
        get_req = self.messages.DnsPoliciesGetRequest(project=self.Project(),
                                                      policy='mypolicy0')
        self.client.policies.Get.Expect(request=get_req, response=get_output)
        if description:
            expected_output.description = 'New Description'

        if networks:
            expected_output.networks = util.GetPolicyNetworks(networks)

        if name_servers or private_name_servers:
            expected_output.alternativeNameServerConfig = (
                util.GetAltNameServerConfig(
                    target_servers=name_servers,
                    private_target_servers=private_name_servers))

        if forwarding is not None:
            expected_output.enableInboundForwarding = forwarding

        if logging is not None:
            expected_output.enableLogging = logging

        update_req = self.messages.DnsPoliciesUpdateRequest(
            policy=expected_output.name,
            policyResource=expected_output,
            project=self.Project())
        expected_response = self.messages.PoliciesUpdateResponse(
            policy=expected_output)
        self.client.policies.Update.Expect(request=update_req,
                                           response=expected_response)

        return expected_response
Ejemplo n.º 7
0
 def testCreateMinimalNetworks(self):
   test_networks = [
       util.GetNetworkURI('default', self.Project()),
       util.GetNetworkURI('network1', self.Project())
   ]
   expected_output = util.GetPolicies(networks=test_networks, num=1).pop()
   create_req = self.messages.DnsPoliciesCreateRequest(
       project=self.Project(), policy=expected_output)
   self.client.policies.Create.Expect(
       request=create_req, response=expected_output)
   actual_output = self.Run('dns policies create mypolicy0 --description '
                            '"My policy 0" --networks default,network1')
   self.assertEqual(expected_output, actual_output)