예제 #1
0
 def _get_rt(self, fq_name, parent):
     rt = Resource('route-table', fq_name=fq_name, parent=parent)
     try:
         rt.fetch()
     except ResourceNotFound:
         rt['routes'] = {'route': []}
         if not self.dry_run:
             rt.save()
     return rt
    def test_resource_fetch(self, mock_session):
        mock_session.configure_mock(base_url=self.BASE)

        mock_session.fqname_to_id.side_effect = HttpError(http_status=404)
        r = Resource('foo', fq_name='domain:bar:foo')
        with self.assertRaises(ResourceNotFound):
            r.fetch()

        mock_session.fqname_to_id.side_effect = [
            "07eeb3c0-42f5-427c-9409-6ae45b376aa2"
        ]
        mock_session.get_json.return_value = {
            'foo': {
                'uuid': '07eeb3c0-42f5-427c-9409-6ae45b376aa2',
                'fq_name': ['domain', 'bar', 'foo']
            }
        }
        r = Resource('foo', fq_name='domain:bar:foo')
        r.fetch()
        self.assertEqual(r.uuid, '07eeb3c0-42f5-427c-9409-6ae45b376aa2')
        mock_session.get_json.assert_called_with(r.href)

        r.fetch(exclude_children=True)
        mock_session.get_json.assert_called_with(r.href, exclude_children=True)

        r.fetch(exclude_back_refs=True)
        mock_session.get_json.assert_called_with(r.href,
                                                 exclude_back_refs=True)
예제 #3
0
    def test_resource_fetch(self, mock_session):
        mock_session.configure_mock(base_url=BASE)

        mock_session.fqname_to_id.side_effect = HttpError(http_status=404)
        r = Resource('foo', fq_name='domain:bar:foo')
        with self.assertRaises(ResourceNotFound):
            r.fetch()

        mock_session.fqname_to_id.side_effect = [
            "07eeb3c0-42f5-427c-9409-6ae45b376aa2"
        ]
        mock_session.get_json.return_value = {
            'foo': {
                'uuid': '07eeb3c0-42f5-427c-9409-6ae45b376aa2',
                'fq_name': ['domain', 'bar', 'foo']
            }
        }
        r = Resource('foo', fq_name='domain:bar:foo')
        r.fetch()
        self.assertEqual(r.uuid, '07eeb3c0-42f5-427c-9409-6ae45b376aa2')
        mock_session.get_json.assert_called_with(r.href)

        r.fetch(exclude_children=True)
        mock_session.get_json.assert_called_with(r.href, exclude_children=True)

        r.fetch(exclude_back_refs=True)
        mock_session.get_json.assert_called_with(r.href, exclude_back_refs=True)
예제 #4
0
 def test_exist_exception(self, mock_session):
     r = Resource('foo', uuid='ec1afeaa-8930-43b0-a60a-939f23a50724')
     test_suite = [
         ("Delete when children still present: %s" %
          ['http://host%s' % r.path], ChildrenExists),
         ("Children http://host%s still exist" % r.path, ChildrenExists),
         ("Delete when resource still referred: %s" %
          ['http://host%s' % r.path], BackRefsExists),
         ("Back-References from http://host%s still exist" % r.path,
          BackRefsExists),
         ("Cannot modify system resource %s %s(%s)" %
          (r.type, r.fq_name, r.uuid), IsSystemResource),
     ]
     for msg, exception in test_suite:
         mock_session.get_json.side_effect = HttpError(http_status=409,
                                                       message=msg)
         with self.assertRaises(exception) as e:
             r.fetch()
             self.assertListEqual([r], e.exception.resources)