예제 #1
0
    def post(self, new_contract):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:contract:create', cdict, cdict)

        contract_dict = new_contract.to_dict()
        contract_dict['project_id'] = request.project_id
        contract_dict['uuid'] = uuidutils.generate_uuid()

        if new_contract.offer_uuid_or_name is None:
            raise exception.ContractNoOfferUUID()

        related_offer = utils.get_offer(new_contract.offer_uuid_or_name,
                                        statuses.AVAILABLE)

        contract_dict['offer_uuid'] = related_offer.uuid

        if 'start_time' not in contract_dict:
            contract_dict['start_time'] = datetime.datetime.now()

        if 'end_time' not in contract_dict:
            q = related_offer.get_first_availability(
                contract_dict['start_time'])
            if q is None:
                contract_dict['end_time'] = related_offer.end_time
            else:
                contract_dict['end_time'] = q.start_time

        c = contract.Contract(**contract_dict)
        c.create(request)
        return Contract(**c.to_dict())
예제 #2
0
파일: base.py 프로젝트: ljmcgann/esi-leap
 def create_test_contract(context):
     c = contract.Contract(
         start_date=datetime.datetime(2016, 7, 16, 19, 20, 30),
         end_date=datetime.datetime(2016, 8, 16, 19, 20, 30),
         offer_uuid='1234567890',
         project_id="222222222222")
     c.create(context)
     return c
예제 #3
0
    def test_destroy(self):
        c = contract.Contract(self.context, **self.fake_contract)
        with mock.patch.object(self.db_api, 'contract_destroy',
                               autospec=True) as mock_contract_cancel:

            c.destroy()

            mock_contract_cancel.assert_called_once_with(c.uuid)
예제 #4
0
    def post(self, new_contract):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:contract:create', cdict, cdict)

        c = contract.Contract(**new_contract.to_dict())
        c.create(request)
        return Contract(**c.to_dict())
예제 #5
0
    def test_create(self):
        c = contract.Contract(self.context, **self.fake_contract)
        with mock.patch.object(self.db_api, 'contract_create',
                               autospec=True) as mock_contract_create:
            mock_contract_create.return_value = get_test_contract()

            c.create(self.context)

            mock_contract_create.assert_called_once_with(
                self.context, get_test_contract())
예제 #6
0
    def setUp(self):

        self.context = lessee_ctx

        super(TestContractsControllerAdmin, self).setUp()

        o = create_test_offer(self.context)

        self.test_contract = contract.Contract(
            start_date=datetime.datetime(2016, 7, 16, 19, 20, 30),
            end_date=datetime.datetime(2016, 8, 16, 19, 20, 30),
            uuid='1111111111',
            offer_uuid=o.uuid,
            project_id=lessee_ctx.project_id)
예제 #7
0
 def _retrieve_contracts(self):
     LOG.info("Checking for new contracts in marketplace")
     contracts = flocx_market.retrieve_from_flocx_market(self._context)
     for c in contracts:
         co = contract.Contract(self._context, **c)
         co.create(self._context)
         LOG.info("Creating contract %s", co.uuid)
         o_c_r_id = c["marketplace_offer_contract_relationship_id"]
         res_status_code = flocx_market.update_flocx_market_contract(
             o_c_r_id)
         if res_status_code == 200:
             LOG.info(
                 "Updating offer contract pair in marketplace for offer %s",
                 o_c_r_id)
예제 #8
0
    def test_create_concurrent(self):
        c = contract.Contract(self.context, **self.fake_contract)

        c2 = contract.Contract(self.context, **self.fake_contract)

        c2.id = 28

        o = get_offer()

        with mock.patch.object(self.db_api, 'contract_create',
                               autospec=True) as mock_contract_create:
            with mock.patch.object(self.db_api,
                                   'offer_get_by_uuid',
                                   autospec=True) as mock_offer_get:
                with mock.patch.object(self.db_api,
                                       'offer_verify_contract_availability',
                                       autospec=True) as mock_ovca:

                    mock_offer_get.return_value = o

                    def update_mock(updates):
                        mock_ovca.side_effect = Exception("bad")

                    mock_contract_create.side_effect = update_mock

                    thread = threading.Thread(target=c.create)
                    thread2 = threading.Thread(target=c2.create)

                    thread.start()
                    thread2.start()

                    thread.join()
                    thread2.join()

                    assert mock_offer_get.call_count == 2
                    assert mock_ovca.call_count == 2
                    mock_contract_create.assert_called_once()
예제 #9
0
    def test_create(self, mock_offer_get):
        c = contract.Contract(self.context, **self.fake_contract)
        with mock.patch.object(self.db_api, 'contract_create',
                               autospec=True) as mock_contract_create:
            with mock.patch.object(self.db_api,
                                   'offer_get_by_uuid',
                                   autospec=True) as mock_offer_get:
                mock_contract_create.return_value = get_test_contract_1()
                mock_offer_get.return_value = get_offer()

                c.create('534653c9-880d-4c2d-6d6d-f4f2a09e384')

                mock_contract_create.assert_called_once_with(
                    get_test_contract_1())
                mock_offer_get.assert_called_once_with(
                    '534653c9-880d-4c2d-6d6d-f4f2a09e384')
예제 #10
0
    def test_create(self):
        c = contract.Contract(self.context, **self.fake_contract)
        with mock.patch.object(self.db_api, 'contract_create',
                               autospec=True) as mock_contract_create:
            with mock.patch.object(self.db_api,
                                   'offer_get_by_uuid',
                                   autospec=True) as mock_offer_get_by_uuid:
                with mock.patch(
                        'esi_leap.objects.contract.uuidutils.generate_uuid')\
                        as mock_uuid:
                    mock_offer_get_by_uuid.return_value = get_offer()
                    mock_contract_create.return_value = get_test_contract_1()
                    mock_uuid.return_value = '534653c9-880d-4c2d-6d6d-' \
                                             '11111111111'

                    c.create()

                    mock_contract_create.assert_called_once_with(
                        get_test_contract_1())
예제 #11
0
    def test_create(self):
        c = contract.Contract(self.context, **self.fake_contract)
        with mock.patch.object(self.db_api, 'contract_create',
                               autospec=True) as mock_contract_create:
            with mock.patch.object(self.db_api,
                                   'offer_get_by_uuid',
                                   autospec=True) as mock_offer_get:
                with mock.patch.object(self.db_api,
                                       'offer_verify_contract_availability',
                                       autospec=True):

                    mock_contract_create.return_value = get_test_contract_1()
                    mock_offer_get.return_value = get_offer()

                    c.create()

                    mock_contract_create.assert_called_once_with(
                        get_test_contract_1())
                    mock_offer_get.assert_called_once()
예제 #12
0
    def test_save(self):
        c = contract.Contract(self.context, **self.fake_contract)
        new_status = statuses.ACTIVE
        updated_at = datetime.datetime(2006, 12, 11, 0, 0)
        with mock.patch.object(self.db_api, 'contract_update',
                               autospec=True) as mock_contract_update:
            updated_contract = get_test_contract_1()
            updated_contract['status'] = new_status
            updated_contract['updated_at'] = updated_at
            mock_contract_update.return_value = updated_contract

            c.status = new_status
            c.save(self.context)

            updated_values = get_test_contract_1()
            updated_values['status'] = new_status
            mock_contract_update.assert_called_once_with(
                c.uuid, updated_values)
            self.assertEqual(self.context, c._context)
            self.assertEqual(updated_at, c.updated_at)
예제 #13
0
    def test_create_invalid_time(self):
        bad_contract = {
            'id': 30,
            'name': 'c2',
            'uuid': '534653c9-880d-4c2d-6d6d-44444444444',
            'project_id': 'le55ee_2',
            'start_time': start + datetime.timedelta(days=30),
            'end_time': start + datetime.timedelta(days=20),
            'fulfill_time': start + datetime.timedelta(days=35),
            'expire_time': start + datetime.timedelta(days=40),
            'status': statuses.CREATED,
            'properties': {},
            'offer_uuid': '534653c9-880d-4c2d-6d6d-f4f2a09e384',
            'created_at': None,
            'updated_at': None
        }

        c = contract.Contract(self.context, **bad_contract)

        self.assertRaises(exception.InvalidTimeRange, c.create)
예제 #14
0
    def post(self, new_contract):
        request = pecan.request.context
        cdict = request.to_policy_values()
        policy.authorize('esi_leap:contract:create', cdict, cdict)

        contract_dict = new_contract.to_dict()
        contract_dict['project_id'] = request.project_id
        contract_dict['uuid'] = uuidutils.generate_uuid()

        if new_contract.offer_uuid_or_name is None:
            raise exception.ContractNoOfferUUID()

        o_objects = offer.Offer.get(new_contract.offer_uuid_or_name)
        if len(o_objects) > 1:
            raise exception.OfferDuplicateName(
                name=new_contract.offer_uuid_or_name)
        elif len(o_objects) == 0:
            raise exception.OfferNotFound(
                offer_uuid=new_contract.offer_uuid_or_name)

        related_offer = o_objects[0]
        contract_dict['offer_uuid'] = related_offer.uuid

        if 'start_time' not in contract_dict:
            contract_dict['start_time'] = datetime.datetime.now()

        if 'end_time' not in contract_dict:
            q = related_offer.get_first_availability(
                contract_dict['start_time'])
            if q is None:
                contract_dict['end_time'] = related_offer.end_time
            else:
                contract_dict['end_time'] = q.start_time

        c = contract.Contract(**contract_dict)
        c.create(request)
        return Contract(**c.to_dict())
예제 #15
0
        "end_time": "2016-08-16T19:20:30"
    }


test_offer = offer.Offer(resource_type='test_node',
                         resource_uuid=test_node_1._uuid,
                         name="o",
                         uuid='11111',
                         status=statuses.AVAILABLE,
                         start_time=start,
                         end_time=end,
                         project_id=owner_ctx.project_id)

test_contract = contract.Contract(offer_uuid="11111",
                                  name='c',
                                  uuid='zzzzz',
                                  project_id=lessee_ctx.project_id,
                                  status=statuses.CREATED)

test_contract_2 = contract.Contract(offer_uuid="11111",
                                    name='c',
                                    uuid='yyyyy',
                                    project_id=lessee_ctx.project_id,
                                    status=statuses.CREATED)

test_contract_3 = contract.Contract(offer_uuid="11111",
                                    name='c',
                                    uuid='xxxxx',
                                    project_id=lessee_ctx_2.project_id,
                                    status=statuses.CREATED)
예제 #16
0
test_offer = offer.Offer(
    resource_type='test_node',
    resource_uuid='abc',
    name="o",
    uuid=o_uuid,
    status=statuses.AVAILABLE,
    start_time=datetime.datetime(3000, 7, 16),
    end_time=datetime.datetime(4000, 7, 16),
    project_id=owner_ctx.project_id
)

test_contract = contract.Contract(
    offer_uuid=o_uuid,
    name='c',
    uuid=uuidutils.generate_uuid(),
    project_id=lessee_ctx.project_id,
    status=statuses.CREATED,
    start_time=datetime.datetime(3000, 7, 16),
    end_time=datetime.datetime(4000, 7, 16),
)


@mock.patch('esi_leap.manager.service.timeutils.utcnow')
@mock.patch('esi_leap.manager.service.LOG.info')
@mock.patch('esi_leap.manager.service.contract.Contract.get_all')
def test__fulfill_contracts(mock_ga, mock_log, mock_utcnow):
    mock_ga.return_value = [test_contract]
    mock_utcnow.return_value = datetime.datetime(3500, 7, 16)

    s = ManagerService()
예제 #17
0
        "end_time": "2016-08-16T19:20:30"
    }


test_offer = offer.Offer(resource_type='test_node',
                         resource_uuid=test_node_1._uuid,
                         name="o",
                         uuid=o_uuid,
                         status=statuses.AVAILABLE,
                         start_time=start,
                         end_time=end,
                         project_id=owner_ctx.project_id)

test_contract = contract.Contract(offer_uuid=o_uuid,
                                  name='c',
                                  uuid=c_uuid,
                                  project_id=lessee_ctx.project_id,
                                  status=statuses.CREATED)

test_contract_2 = contract.Contract(offer_uuid=o_uuid,
                                    name='c',
                                    uuid=uuidutils.generate_uuid(),
                                    project_id=lessee_ctx.project_id,
                                    status=statuses.CREATED)

test_contract_3 = contract.Contract(offer_uuid=o_uuid,
                                    name='c',
                                    uuid=uuidutils.generate_uuid(),
                                    project_id=lessee_ctx_2.project_id,
                                    status=statuses.CREATED)