def process_order(order_id, keystone_id): """Process Order.""" LOG.debug('Order id is {0}'.format(order_id)) task = BeginOrder() try: task.process(order_id, keystone_id) except Exception: LOG.exception(">>>>> Task exception seen, but simulating async " "reporting via the Orders entity on the worker side.")
def setUp(self): self.requestor = 'requestor1234' self.order = Order() self.order.id = "id1" self.order.requestor = self.requestor self.secret_name = "name" self.secret_algorithm = "algo" self.secret_bit_length = 512 self.secret_cypher_type = "cytype" self.secret_mime_type = "text/plain" self.secret_expiration = timeutils.utcnow() self.keystone_id = 'keystone1234' self.tenant_id = 'tenantid1234' self.tenant = Tenant() self.tenant.id = self.tenant_id self.tenant.keystone_id = self.keystone_id self.tenant_repo = MagicMock() self.tenant_repo.get.return_value = self.tenant self.order.status = States.PENDING self.order.tenant_id = self.tenant_id self.order.secret_name = self.secret_name self.order.secret_algorithm = self.secret_algorithm self.order.secret_bit_length = self.secret_bit_length self.order.secret_cypher_type = self.secret_cypher_type self.order.secret_expiration = self.secret_expiration self.order.secret_mime_type = self.secret_mime_type self.order_repo = MagicMock() self.order_repo.get.return_value = self.order self.secret_repo = MagicMock() self.secret_repo.create_from.return_value = None self.tenant_secret_repo = MagicMock() self.tenant_secret_repo.create_from.return_value = None self.datum_repo = MagicMock() self.datum_repo.create_from.return_value = None self.conf = MagicMock() self.conf.crypto.namespace = 'barbican.test.crypto.plugin' self.conf.crypto.enabled_crypto_plugins = ['test_crypto'] self.crypto_mgr = CryptoExtensionManager(conf=self.conf) self.resource = BeginOrder(self.crypto_mgr, self.tenant_repo, self.order_repo, self.secret_repo, self.tenant_secret_repo, self.datum_repo)
def setUp(self): self.requestor = 'requestor1234' self.order = Order() self.order.id = "id1" self.order.requestor = self.requestor self.secret_name = "name" self.secret_algorithm = "algo" self.secret_bit_length = 512 self.secret_cypher_type = "cytype" self.secret_mime_type = "mimetype" self.secret_expiration = timeutils.utcnow() self.keystone_id = 'keystone1234' self.tenant_id = 'tenantid1234' self.tenant = Tenant() self.tenant.id = self.tenant_id self.tenant.keystone_id = self.keystone_id self.tenant_repo = MagicMock() self.tenant_repo.get.return_value = self.tenant self.order.status = States.PENDING self.order.tenant_id = self.tenant_id self.order.secret_name = self.secret_name self.order.secret_algorithm = self.secret_algorithm self.order.secret_bit_length = self.secret_bit_length self.order.secret_cypher_type = self.secret_cypher_type self.order.secret_expiration = self.secret_expiration self.order.secret_mime_type = self.secret_mime_type self.order_repo = MagicMock() self.order_repo.get.return_value = self.order self.secret_repo = MagicMock() self.secret_repo.create_from.return_value = None self.tenant_secret_repo = MagicMock() self.tenant_secret_repo.create_from.return_value = None self.datum_repo = MagicMock() self.datum_repo.create_from.return_value = None self.resource = BeginOrder(self.tenant_repo, self.order_repo, self.secret_repo, self.tenant_secret_repo, self.datum_repo)
class WhenBeginningOrder(unittest.TestCase): def setUp(self): self.requestor = 'requestor1234' self.order = Order() self.order.id = "id1" self.order.requestor = self.requestor self.secret_name = "name" self.secret_algorithm = "algo" self.secret_bit_length = 512 self.secret_cypher_type = "cytype" self.secret_mime_type = "text/plain" self.secret_expiration = timeutils.utcnow() self.keystone_id = 'keystone1234' self.tenant_id = 'tenantid1234' self.tenant = Tenant() self.tenant.id = self.tenant_id self.tenant.keystone_id = self.keystone_id self.tenant_repo = MagicMock() self.tenant_repo.get.return_value = self.tenant self.order.status = States.PENDING self.order.tenant_id = self.tenant_id self.order.secret_name = self.secret_name self.order.secret_algorithm = self.secret_algorithm self.order.secret_bit_length = self.secret_bit_length self.order.secret_cypher_type = self.secret_cypher_type self.order.secret_expiration = self.secret_expiration self.order.secret_mime_type = self.secret_mime_type self.order_repo = MagicMock() self.order_repo.get.return_value = self.order self.secret_repo = MagicMock() self.secret_repo.create_from.return_value = None self.tenant_secret_repo = MagicMock() self.tenant_secret_repo.create_from.return_value = None self.datum_repo = MagicMock() self.datum_repo.create_from.return_value = None self.conf = MagicMock() self.conf.crypto.namespace = 'barbican.test.crypto.plugin' self.conf.crypto.enabled_crypto_plugins = ['test_crypto'] self.crypto_mgr = CryptoExtensionManager(conf=self.conf) self.resource = BeginOrder(self.crypto_mgr, self.tenant_repo, self.order_repo, self.secret_repo, self.tenant_secret_repo, self.datum_repo) def test_should_process_order(self): self.resource.process(self.order.id, self.keystone_id) self.order_repo.get \ .assert_called_once_with(entity_id=self.order.id, keystone_id=self.keystone_id) assert self.order.status == States.ACTIVE args, kwargs = self.secret_repo.create_from.call_args secret = args[0] assert isinstance(secret, Secret) assert secret.name == self.secret_name assert secret.expiration == self.secret_expiration args, kwargs = self.tenant_secret_repo.create_from.call_args tenant_secret = args[0] assert isinstance(tenant_secret, TenantSecret) assert tenant_secret.tenant_id == self.tenant_id assert tenant_secret.secret_id == secret.id args, kwargs = self.datum_repo.create_from.call_args datum = args[0] self.assertIsInstance(datum, EncryptedDatum) self.assertEqual(self.secret_mime_type, datum.mime_type) assert datum.cypher_text is not None assert datum.kek_metadata is not None
def process_order_wrapper(order_id, keystone_id): """(Celery wrapped task) Process Order.""" LOG.debug('Order id is {0}'.format(order_id)) task = BeginOrder() return task.process(order_id, keystone_id)
def process_order(order_id): """Process Order.""" LOG.debug('Order id is {0}'.format(order_id)) task = BeginOrder() return task.process(order_id)