class TestGlacierSNSAuto(TestGlacierSNS): def test_sync_auto_basic(self): """ No configuration """ sns_options = {'topic': 'aws-glacier-notifications', 'topics_present': False} self.gw = GlacierWrapper(**self.args) vault_name = "test_vvault0" # Lets create one vault for our testing purposes self.gw.mkvault(vault_name) # Only after a call to one of gw functions was executed # is glacierconn available gc = vars(self.gw)['glacierconn'] # No vault notifications set for fresh vault with self.assertRaises(UnexpectedHTTPResponseError) as cm: gc.get_vault_notifications(vault_name) self.assertEqual(cm.exception.status, 404) self.assertEqual(cm.exception.message, ("Expected 200, got (404, " "code=ResourceNotFoundException, " "message=No notification configuration " "is set for vault: %s)") % (vault_name,)) # Set all vaults response = self.gw.sns_sync(sns_options=sns_options, output="csv") successful_vaults = [r["Vault Name"] for r in response] self.assertIn(vault_name, successful_vaults) # Check out vault has set notifications vaults = [vault[u'VaultARN'].split("vaults/")[-1] for vault in self.gw.lsvault()] for vault in vaults: response = gc.get_vault_notifications(vault) events = response['Events'] self.assertIn(u"ArchiveRetrievalCompleted", events) self.assertIn(u"InventoryRetrievalCompleted", events) # Remove test vault self.gw.rmvault(vault_name)
class TestGlacierSNSMultiConfig(TestGlacierSNS): def test_withOUT_method(self): """ Configuration [SNS:test_topic_1] [SNS:test_topic_2] vaults=test_vvault0,test_vvault2 {'topics': [ """ vaults = ['test_vvault0', 'test_vvault1', 'test_vvault2'] vaults_used = [vaults[0], vaults[2]] sns_options = {'topics': [ {'topic': 'test_topic_1', 'options':{}}, {'topic': 'test_topic_2', 'options': {'vaults': ','.join(vaults_used)}} ], 'topics_present': True} self.gw = GlacierWrapper(**self.args) for vault in vaults: self.gw.mkvault(vault) response = self.gw.sns_sync(sns_options=sns_options, output="csv") for obj in response: del obj['Request Id'] # Testing topic 1 - no vaults passed in, # should be subscribed to all vaults (our testing vaults and some more) for vault in vaults: self.assertIn( dict([('Topic', 'test_topic_1'), ('Subscribe Result', u''), ('Vault Name', vault)]), response) # Testing topic 2 # should be subscribed only to test_vvault0, test_vvault2 for vault in vaults_used: self.assertIn( dict([('Topic', 'test_topic_2'), ('Subscribe Result', u''), ('Vault Name', vault)]), response) for vault in vaults: self.gw.rmvault(vault) def test_with_method(self): """ Configuration [SNS:test_topic_1] method=email,[email protected]; [SNS:test_topic_2] vaults=test_vvault0,test_vvault2 method=email,[email protected];email,[email protected] """ vaults = ['test_vvault0', 'test_vvault1', 'test_vvault2'] vaults_used = [vaults[0], vaults[2]] sns_options = {'topics': [ {'topic': 'test_topic_1', 'options': {'method': '%s,%s;' % ( localsettings.protocol_1, localsettings.endpoint_1 )}}, {'topic': 'test_topic_2', 'options': {'vaults': 'test_vvault0,test_vvault2', 'method': ('%s,%s;' '%s,%s') % ( localsettings.protocol_1, localsettings.endpoint_1, localsettings.protocol_2, localsettings.endpoint_2)}} ], 'topics_present': True} self.gw = GlacierWrapper(**self.args) for vault in vaults: self.gw.mkvault(vault) response = self.gw.sns_sync(sns_options=sns_options, output="csv") for obj in response: del obj['Request Id'] # Testing topic 1 - no vaults passed in, # should be subscribed to all vaults (our testing vaults and some more) for vault in vaults: self.assertIn( dict([('Topic', 'test_topic_1'), ('Subscribe Result', u'pending confirmation'), ('Vault Name', vault)]), response) # Testing topic 2 # should be subscribed only to test_vvault0, test_vvault2 for vault in vaults_used: self.assertIn( dict([('Topic', 'test_topic_2'), ('Subscribe Result', u'pending confirmation'), ('Vault Name', vault)]), response) for vault in vaults: self.gw.rmvault(vault)