Esempio n. 1
0
    def testCreateWithServiceDirectoryAndPrivateVisibility(self):
        sd_url = ('https://servicedirectory.googleapis.com/v1/projects'
                  'my-project/locations/us-central1/namespaces/my-namespace')
        service_directory_config = util_beta.ServiceDirectoryConfig(sd_url)
        visibility_settings = util.GetDnsVisibilityDict(
            self.api_version,
            visibility='private',
            network_urls=['1.0.2.1', '1.2.2.1'],
            messages=self.messages)

        test_zone = util_beta.GetManagedZoneBeforeCreation(
            self.messages,
            visibility_dict=visibility_settings,
            service_directory_config=service_directory_config)

        zone_create_request = self.messages.DnsManagedZonesCreateRequest(
            managedZone=test_zone, project=self.Project())
        self.client.managedZones.Create.Expect(zone_create_request, test_zone)

        self.Run(
            'dns managed-zones create {0} --dns-name {1} --description {2} '
            '--format=disable --visibility private --networks {3} '
            '--service-directory-namespace {4}'.format(
                test_zone.name, test_zone.dnsName, test_zone.description,
                ','.join(['1.0.2.1', '1.2.2.1']), sd_url))
Esempio n. 2
0
    def testCreateWithBothKindsOfForwardingTargetsAndPrivateVisibility(self):
        forwarding_servers = ['1.0.1.1', '1.2.1.1']
        private_forwarding_targets = ['1.1.1.1', '8.8.8.8']
        forwarding_config = util.ParseManagedZoneForwardingConfig(
            target_servers=forwarding_servers,
            private_target_servers=private_forwarding_targets)

        visibility_settings = util.GetDnsVisibilityDict(
            self.api_version,
            visibility='private',
            network_urls=['1.0.2.1', '1.2.2.1'])
        test_zone = util.GetManagedZoneBeforeCreation(
            self.messages,
            dns_sec_config=False,
            visibility_dict=visibility_settings,
            forwarding_config=forwarding_config)

        zone_create_request = self.messages.DnsManagedZonesCreateRequest(
            managedZone=test_zone, project=self.Project())
        self.client.managedZones.Create.Expect(zone_create_request, test_zone)
        result = self.Run(
            'dns managed-zones create {0} --dns-name {1} --description {2} '
            '--format=disable --visibility private --forwarding-targets {3} '
            '--private-forwarding-targets {4} --networks {5}'.format(
                test_zone.name, test_zone.dnsName, test_zone.description,
                ','.join(forwarding_servers),
                ','.join(private_forwarding_targets),
                ','.join(['1.0.2.1', '1.2.2.1'])))

        self.assertEqual([test_zone], list(result))
        self.AssertOutputEquals('')
        self.AssertErrContains("""\
Created [{0}projects/{1}/managedZones/mz].
""".format(self.client.BASE_URL, self.Project()))
Esempio n. 3
0
 def testCreateWithPrivateVisibilityAndMissingNetworks(self):
     visibility_settings = util.GetDnsVisibilityDict(self.api_version,
                                                     visibility='private',
                                                     messages=self.messages)
     test_zone = util.GetManagedZoneBeforeCreation(
         self.messages,
         dns_sec_config=False,
         visibility_dict=visibility_settings)
     with self.assertRaises(exceptions.RequiredArgumentException):
         self.Run(
             'dns managed-zones create {0} --dns-name {1} --description {2} '
             '--format=disable --visibility private'.format(
                 test_zone.name, test_zone.dnsName, test_zone.description))
Esempio n. 4
0
 def testCreateWithForwardingTargetsandPublicVisibility(self):
     visibility_settings = util.GetDnsVisibilityDict(self.api_version,
                                                     visibility='private',
                                                     network_urls=[])
     test_zone = util.GetManagedZoneBeforeCreation(
         self.messages,
         dns_sec_config=False,
         visibility_dict=visibility_settings)
     with self.assertRaises(exceptions.InvalidArgumentException):
         self.Run(
             'dns managed-zones create {0} --dns-name {1} --description {2} '
             '--format=disable --visibility public '
             '--forwarding-targets 1.0.0.1 --networks 1.0.0.1'.format(
                 test_zone.name, test_zone.dnsName, test_zone.description))
Esempio n. 5
0
    def testCreateWithPublicVisibility(self):
        visibility_settings = util.GetDnsVisibilityDict(self.api_version,
                                                        messages=self.messages)
        test_zone = util.GetManagedZoneBeforeCreation(
            self.messages,
            dns_sec_config=False,
            visibility_dict=visibility_settings)
        zone_create_request = self.messages.DnsManagedZonesCreateRequest(
            managedZone=test_zone, project=self.Project())
        self.client.managedZones.Create.Expect(zone_create_request, test_zone)
        result = self.Run(
            'dns managed-zones create {0} --dns-name {1} --description {2} '
            '--format=disable --visibility public'.format(
                test_zone.name, test_zone.dnsName, test_zone.description))
        self.assertEqual([test_zone], list(result))
        self.AssertOutputEquals('')
        self.AssertErrContains("""\
Created [{0}projects/{1}/managedZones/mz].
""".format(self.client.BASE_URL, self.Project()))
Esempio n. 6
0
    def testCreateWithPrivateVisibilityErrors(self):
        visibility_settings = util.GetDnsVisibilityDict(self.api_version,
                                                        visibility='private',
                                                        network_urls=[],
                                                        messages=self.messages)
        test_zone = util.GetManagedZoneBeforeCreation(
            self.messages,
            dns_sec_config=False,
            visibility_dict=visibility_settings)

        with self.assertRaisesRegexp(
                exceptions.RequiredArgumentException,
                r'Missing required argument \[--networks\]'):
            self.Run(
                'dns managed-zones create {0} --dns-name {1} --description {2} '
                '--format=disable --visibility private'.format(
                    test_zone.name, test_zone.dnsName, test_zone.description))

        with self.assertRaises(exceptions.InvalidArgumentException):
            self.Run(
                'dns managed-zones create {0} --dns-name {1} --description {2} '
                '--format=disable --visibility public --networks 1.0.0.1'.
                format(test_zone.name, test_zone.dnsName,
                       test_zone.description))