def test_validate(self): """ Test validation method """ param = None self.assertRaises(ValueError, UpgradeMessageSender._validate, param, 36) param = "" self.assertRaises(ValueError, UpgradeMessageSender._validate, param, 36) param = "7169f46a-ac53-401a-ba35-f461db948b8c7" self.assertRaises(ValueError, UpgradeMessageSender._validate, param, 36) param = "7169f46a-ac53-401a-ba35-f461db948b8c" self.assertTrue(UpgradeMessageSender._validate(param, 36)) param = "7169f46a-ac53-401a-ba35" self.assertTrue(UpgradeMessageSender._validate(param, 36))
def _assert_create_with_metadata(self, mock_client, api_upgrade_mock, metadata=None): """Excercise UpgradeMessageSender.create() call. """ context = Mock() instance_id = "27e25b73-88a1-4526-b2b9-919a28b8b33f" instance_version = "v1.0.1" location = "http://swift/trove-guestagent-v1.0.1.tar.gz" func = ( UpgradeMessageSender.create(context, instance_id, instance_version, location, metadata) if metadata is not None else UpgradeMessageSender.create(context, instance_id, instance_version, location) ) self.assertTrue(callable(func)) func() # This call should translate to the API call asserted below. api_upgrade_mock.assert_called_once_with(instance_version, location, metadata)
def _assert_create_with_metadata(self, mock_client, api_upgrade_mock, metadata=None): """Exercise UpgradeMessageSender.create() call. """ context = trove_testtools.TroveTestContext(self) instance_id = "27e25b73-88a1-4526-b2b9-919a28b8b33f" instance_version = "v1.0.1" location = "http://swift/trove-guestagent-v1.0.1.tar.gz" func = (UpgradeMessageSender.create( context, instance_id, instance_version, location, metadata) if metadata is not None else UpgradeMessageSender.create( context, instance_id, instance_version, location)) self.assertTrue(callable(func)) func() # This call should translate to the API call asserted below. api_upgrade_mock.assert_called_once_with(instance_version, location, metadata)
def test_validate(self): """ Test validation method """ param = None self.assertRaises(ValueError, UpgradeMessageSender._validate, param, 36) param = '' self.assertRaises(ValueError, UpgradeMessageSender._validate, param, 36) param = '7169f46a-ac53-401a-ba35-f461db948b8c7' self.assertRaises(ValueError, UpgradeMessageSender._validate, param, 36) param = '7169f46a-ac53-401a-ba35-f461db948b8c' self.assertTrue(UpgradeMessageSender._validate(param, 36)) param = '7169f46a-ac53-401a-ba35' self.assertTrue(UpgradeMessageSender._validate(param, 36))
def create(self, req, body, tenant_id, instance_id): LOG.info( _("Sending upgrade notifications\nreq : '%(req)s'\n" "Admin tenant_id: %(tenant_id)s") % {"tenant_id": tenant_id, "req": req} ) context = req.environ.get(wsgi.CONTEXT_KEY) upgrade = body["upgrade"] instance_version = upgrade.get("instance_version") location = upgrade.get("location") metadata = upgrade.get("metadata") send = UpgradeMessageSender.create(context, instance_id, instance_version, location, metadata) send() return wsgi.Result(None, 202)
def create(self, req, body, tenant_id, instance_id): LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Sending upgrade notification")) LOG.debug(_("Admin tenant_id: %s") % tenant_id) context = req.environ.get(wsgi.CONTEXT_KEY) upgrade = body['upgrade'] instance_version = upgrade.get('instance_version') location = upgrade.get('location') metadata = upgrade.get('metadata') send = UpgradeMessageSender.create( context, instance_id, instance_version, location, metadata) send() return wsgi.Result(None, 202)
def test_create(self): """ Test creating notification """ context = Mock() instance_id = "27e25b73-88a1-4526-b2b9-919a28b8b33f", instance_version = "v1.0.1", location = "http://swift/trove-guestagent-v1.0.1.tar.gz" _create_resource = Mock(return_value=None) UpgradeMessageSender.create = Mock(return_value=_create_resource) func = UpgradeMessageSender.create(context, instance_id, instance_version, location) self.assertEqual(_create_resource, func) UpgradeMessageSender.create.assert_called_with( context, instance_id, instance_version, location)
def create(self, req, body, tenant_id, instance_id): LOG.info( _("Sending upgrade notifications\nreq : '%(req)s'\n" "Admin tenant_id: %(tenant_id)s"), { "tenant_id": tenant_id, "req": req }) context = req.environ.get(wsgi.CONTEXT_KEY) upgrade = body['upgrade'] instance_version = upgrade.get('instance_version') location = upgrade.get('location') metadata = upgrade.get('metadata') send = UpgradeMessageSender.create(context, instance_id, instance_version, location, metadata) send() return wsgi.Result(None, 202)
def test_create_with_metadata(self): """ Test creating notification with metadata """ context = Mock() instance_id = "27e25b73-88a1-4526-b2b9-919a28b8b33f", instance_version = "v1.0.1", location = "http://swift/trove-guestagent-v1.0.1.tar.gz" metadata = {"is_public": True, "is_encrypted": True, "config_location": "http://swift/trove-guestagent.conf"} _create_resource = Mock(return_value=None) UpgradeMessageSender.create = Mock(return_value=_create_resource) func = UpgradeMessageSender.create( context, instance_id, instance_version, location, metadata) self.assertEqual(_create_resource, func) UpgradeMessageSender.create.assert_called_with( context, instance_id, instance_version, location, metadata)