예제 #1
0
 def _ensure_missing(self, *batch):
     with self.open_neo4j_session() as tx:
         for subject in batch:
             try:
                 link_props_utils.read(tx, subject)
                 raise AssertionError(
                     'Record {} exist (must not exist)'.format(subject))
             except exc.DBRecordNotFound:
                 pass
예제 #2
0
    def test_put(self):
        link_props = model.LinkProps(self.endpoint_beta,
                                     self.endpoint_gamma,
                                     props={
                                         'cost': 5,
                                         'custom': 'test'
                                     })

        # to make time_create and time_modify different
        link_props.time_create = model.TimeProperty.new_from_java_timestamp(
            link_props.time_create.as_java_timestamp() - 100)

        # to make a difference in time fields, if incorrect values(not from
        # passed object) are used
        time.sleep(0.001)

        self._put(link_props)

        with self.open_neo4j_session() as tx:
            persistent = link_props_utils.read(tx, link_props)
            self.assertEquals(link_props, persistent)

        response = self._get_kafka_response()
        self.assertEqual(message_utils.MI_LINK_PROPS_RESPONSE,
                         response['clazz'])
        self.assertIsNone(response['error'])

        encoded_link_props = share.link_props_request(link_props)
        encoded_link_props = json.loads(json.dumps(encoded_link_props))
        self.assertEqual(encoded_link_props, response['link_props'])
예제 #3
0
    def test_put_and_propagate(self):
        unique_value = str(uuid.uuid4())
        link_props = model.LinkProps(self.endpoint_alpha,
                                     self.endpoint_beta,
                                     props={'test': unique_value})
        self._put(link_props)

        with self.open_neo4j_session() as tx:
            persistent = link_props_utils.read(tx, link_props)
            self.assertEqual(link_props, persistent)

            isl_db = isl_utils.fetch(
                tx, model.InterSwitchLink.new_from_link_props(link_props))
            tx.graph.pull(isl_db)
            self.assertEqual(unique_value, isl_db['test'])
예제 #4
0
    def test_update(self):
        link_props = model.LinkProps(self.endpoint_alpha,
                                     self.endpoint_beta,
                                     props={
                                         'cost': 1,
                                         'extra': 'new'
                                     })
        self._put(link_props)

        with self.open_neo4j_session() as tx:
            persistent = link_props_utils.read(tx, link_props)
            self.assertEqual({
                'cost': 1,
                'extra': 'new',
                'name': 'alpha-beta'
            }, persistent.props)
예제 #5
0
    def link_props_put(self):
        link_props = self._unpack_link_props()
        protected = link_props.extract_protected_props()
        if protected:
            raise exc.UnacceptableDataError(
                link_props, 'property(es) %s is can\'t be changed'.format(
                    ', '.join(repr(x) for x in sorted(protected))))

        with graph.begin() as tx:
            link_props_utils.create_if_missing(tx, link_props)
            link_props_utils.set_props_and_propagate_to_isl(tx, link_props)

            actual_link_props = link_props_utils.read(tx, link_props)

        payload = message_utils.make_link_props_response(
            self.payload, actual_link_props)
        message_utils.send_link_props_response(payload, self.correlation_id)
예제 #6
0
 def _ensure_exists(self, *batch):
     with self.open_neo4j_session() as tx:
         for subject in batch:
             link_props_utils.read(tx, subject)
예제 #7
0
 def _ensure_props_match(self, link_props, props):
     with self.open_neo4j_session() as tx:
         persistent = link_props_utils.read(tx, link_props)
         self.assertEqual(props, persistent.props)