def testTransactionStart(self): test_zone = util.GetManagedZones()[0] self.mocked_dns_v1.managedZones.Get.Expect( self.messages.DnsManagedZonesGetRequest(managedZone=test_zone.name, project=self.Project()), test_zone) self.mocked_dns_v1.resourceRecordSets.List.Expect( self.messages.DnsResourceRecordSetsListRequest( project=self.Project(), managedZone=test_zone.name, name=test_zone.dnsName, type='SOA', maxResults=100), self.messages.ResourceRecordSetsListResponse( rrsets=util.GetRecordSets()[2:3])) self.Run('dns record-sets transaction start -z {0} '.format( test_zone.name)) self.AssertErrContains('Transaction started [{0}].'.format( transaction_util.DEFAULT_PATH)) with open(transaction_util.DEFAULT_PATH) as results: with open(self.initial_transaction) as expected: self.assertEqual(expected.readlines(), results.readlines()) os.remove(transaction_util.DEFAULT_PATH)
def _ImportReplaceFromFileHelper(self, file_path, flags=None): test_zone = util.GetManagedZones()[0] self.mocked_dns_v1.managedZones.Get.Expect( self.messages.DnsManagedZonesGetRequest(managedZone=test_zone.name, project=self.Project()), test_zone) self.mocked_dns_v1.resourceRecordSets.List.Expect( self.messages.DnsResourceRecordSetsListRequest( project=self.Project(), managedZone=test_zone.name, maxResults=100), self.messages.ResourceRecordSetsListResponse( rrsets=util.GetRecordSets())) self.mocked_dns_v1.changes.Create.Expect( self.messages.DnsChangesCreateRequest( change=util.GetImportReplaceChange(), managedZone=test_zone.name, project=self.Project()), util.GetImportReplaceChangeAfterCreation()) self.Run([ 'dns', 'record-sets', 'import', '-z', test_zone.name, file_path, '--delete-all-existing', '--replace-origin-ns' ] + (flags or [])) self.AssertOutputContains( textwrap.dedent("""\ ID START_TIME STATUS 2 today 5 mins ago done """)) self.AssertErrContains("""\ Created [{0}projects/{1}/managedZones/mz/changes/2]. """.format(self.client.BASE_URL, self.Project()))
def _ImportFromFileHelper(self, file_path, flags=None): test_zone = util.GetManagedZones()[0] self.mocked_dns_v1.managedZones.Get.Expect( self.messages.DnsManagedZonesGetRequest(managedZone=test_zone.name, project=self.Project()), test_zone) self.mocked_dns_v1.resourceRecordSets.List.Expect( self.messages.DnsResourceRecordSetsListRequest( project=self.Project(), managedZone=test_zone.name, maxResults=100), self.messages.ResourceRecordSetsListResponse( rrsets=util.GetRecordSets())) self.mocked_dns_v1.changes.Create.Expect( self.messages.DnsChangesCreateRequest( change=util.GetImportChange(), managedZone=test_zone.name, project=self.Project()), util.GetImportChangeAfterCreation()) self.Run( ['dns', 'record-sets', 'import', '-z', test_zone.name, file_path] + (flags or [])) self.AssertOutputContains( textwrap.dedent("""\ ID START_TIME STATUS 1 today now pending """)) self.AssertErrContains( ('Created [{0}projects/{1}/' 'managedZones/mz/changes/1]').format(self.client.BASE_URL, self.Project()))
def testComputeChangeNoConflicts(self): current_record_sets = dict( ((record_set.name, record_set.type), record_set) for record_set in util.GetRecordSets()) change = import_util.ComputeChange( current_record_sets, util.GetImportedRecordSetsWithoutConflicts(), False, 'zone.com.', True) self.assertEqual(util.GetImportChange(), change)
def testTransactionRemoveBeforeStart(self): test_zone = util.GetManagedZones()[0] test_record = util.GetRecordSets()[0] with self.assertRaises(transaction_util.TransactionFileNotFound) as context: self.Run('dns record-sets transaction remove -z {0} --name {1} --ttl {2}' ' --type {3} {4}'.format(test_zone.name, test_record.name, test_record.ttl, test_record.type, test_record.rrdatas[0])) self.assertEqual(context.exception.message, 'Transaction not found at [{0}]'.format( transaction_util.DEFAULT_PATH))
def testComputeChangeConflicts(self): current_record_sets = dict( ((record_set.name, record_set.type), record_set) for record_set in util.GetRecordSets()) with self.assertRaises(import_util.ConflictingRecordsFound) as context: import_util.ComputeChange(current_record_sets, util.GetImportedRecordSets(), False, 'zone.com.', True) self.assertEqual( context.exception.message, 'The following records (name type) already exist: ' '[\'mail.zone.com. A\', \'zone.com. A\', \'zone.com. SOA\']')
def testComputeChangeReplaceAll(self): current_record_sets = dict( ((record_set.name, record_set.type), record_set) for record_set in util.GetRecordSets()) change = import_util.ComputeChange(current_record_sets, util.GetImportedRecordSets(), True, 'zone.com.', True) self.assertEqual(util.GetImportReplaceChange(), change) change = import_util.ComputeChange(current_record_sets, util.GetImportedRecordSets(), True, 'zone.com.', False) self.assertEqual(util.GetImportReplaceChangeNoReplaceOrigin(), change)
def testRecordSetsListWithLimit(self): test_zone = util.GetManagedZones()[0] self.mocked_dns_v1.resourceRecordSets.List.Expect( self.messages.DnsResourceRecordSetsListRequest( project=self.Project(), managedZone=test_zone.name, maxResults=3), self.messages.ResourceRecordSetsListResponse( rrsets=util.GetRecordSets())) self.Run('dns record-sets list -z {0} --limit=3'.format(test_zone.name)) self.AssertOutputContains("""\ NAME TYPE TTL DATA zone.com. A 21600 1.2.3.4 zone.com. NS 21600 ns-cloud-e1.googledomains.com.,ns-cloud-e2.googledomains.com.,ns-cloud-e3.googledomains.com.,ns-cloud-e4.googledomains.com. zone.com. SOA 21601 ns-cloud-e1.googledomains.com. dns-admin.google.com. 2 21600 3600 1209600 300 """, normalize_space=True)
def testTransactionAddDatum(self): shutil.copyfile( self.initial_transaction, transaction_util.DEFAULT_PATH) test_zone = util.GetManagedZones()[0] test_record = util.GetRecordSets()[0] self.Run( 'dns record-sets transaction add -z {0} --name {1} --ttl {2} --type ' '{3} {4}'.format(test_zone.name, test_record.name, test_record.ttl, test_record.type, test_record.rrdatas[0])) self.AssertErrContains( 'Record addition appended to transaction at [{0}].'.format( transaction_util.DEFAULT_PATH)) with open(self.initial_transaction) as expected: expected_change = transaction_util.ChangeFromYamlFile(expected) expected_change.additions.append(test_record) with open(transaction_util.DEFAULT_PATH) as actual: actual_change = transaction_util.ChangeFromYamlFile(actual) self.assertEqual(expected_change, actual_change)
def testDomainWithoutTrailingDot(self): self._TransactionRemoveHelper(util.GetRecordSets()[0], util.GetRecordSets()[0].name.rstrip('.'))
def testTransactionRemoveDatum(self): self._TransactionRemoveHelper(util.GetRecordSets()[0])
def testTransactionRemoveDifferentRecord(self): self._TransactionRemoveNonExistingHelper( util.GetRecordSets()[0], util.GetRecordSetsForExport()[:1])
def testTransactionRemoveNonExistingRecord(self): self._TransactionRemoveNonExistingHelper(util.GetRecordSets()[0], [])