~cloudbuilders/nova/os-keypair-integration

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/test_images.py

  • Committer: Jesse Andrews
  • Date: 2011-08-26 21:57:53 UTC
  • mfrom: (1455.1.45 nova)
  • Revision ID: anotherjesse@gmail.com-20110826215753-0sfp6dubujsl23wa
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
339
339
        self.stubs.UnsetAll()
340
340
        super(ImageControllerWithGlanceServiceTest, self).tearDown()
341
341
 
 
342
    def _get_fake_context(self):
 
343
        class Context(object):
 
344
            project_id = 'fake'
 
345
        return Context()
 
346
 
342
347
    def _applicable_fixture(self, fixture, user_id):
343
348
        """Determine if this fixture is applicable for given user id."""
344
349
        is_public = fixture["is_public"]
386
391
        self.assertEqual(expected_image, actual_image)
387
392
 
388
393
    def test_get_image_v1_1(self):
389
 
        request = webob.Request.blank('/v1.1/images/124')
 
394
        request = webob.Request.blank('/v1.1/fake/images/124')
390
395
        response = request.get_response(fakes.wsgi_app())
391
396
 
392
397
        actual_image = json.loads(response.body)
393
398
 
394
 
        href = "http://localhost/v1.1/images/124"
395
 
        bookmark = "http://localhost/images/124"
 
399
        href = "http://localhost/v1.1/fake/images/124"
 
400
        bookmark = "http://localhost/fake/images/124"
396
401
        server_href = "http://localhost/v1.1/servers/42"
397
402
        server_bookmark = "http://localhost/servers/42"
398
403
 
508
513
        self.assertEqual(expected.toxml(), actual.toxml())
509
514
 
510
515
    def test_get_image_404_v1_1_json(self):
511
 
        request = webob.Request.blank('/v1.1/images/NonExistantImage')
 
516
        request = webob.Request.blank('/v1.1/fake/images/NonExistantImage')
512
517
        response = request.get_response(fakes.wsgi_app())
513
518
        self.assertEqual(404, response.status_int)
514
519
 
524
529
        self.assertEqual(expected, actual)
525
530
 
526
531
    def test_get_image_404_v1_1_xml(self):
527
 
        request = webob.Request.blank('/v1.1/images/NonExistantImage')
 
532
        request = webob.Request.blank('/v1.1/fake/images/NonExistantImage')
528
533
        request.accept = "application/xml"
529
534
        response = request.get_response(fakes.wsgi_app())
530
535
        self.assertEqual(404, response.status_int)
545
550
        self.assertEqual(expected.toxml(), actual.toxml())
546
551
 
547
552
    def test_get_image_index_v1_1(self):
548
 
        request = webob.Request.blank('/v1.1/images')
 
553
        request = webob.Request.blank('/v1.1/fake/images')
549
554
        response = request.get_response(fakes.wsgi_app())
550
555
 
551
556
        response_dict = json.loads(response.body)
558
563
                fixtures.remove(image)
559
564
                continue
560
565
 
561
 
            href = "http://localhost/v1.1/images/%s" % image["id"]
562
 
            bookmark = "http://localhost/images/%s" % image["id"]
 
566
            href = "http://localhost/v1.1/fake/images/%s" % image["id"]
 
567
            bookmark = "http://localhost/fake/images/%s" % image["id"]
563
568
            test_image = {
564
569
                "id": image["id"],
565
570
                "name": image["name"],
637
642
        self.assertDictListMatch(expected, response_list)
638
643
 
639
644
    def test_get_image_details_v1_1(self):
640
 
        request = webob.Request.blank('/v1.1/images/detail')
 
645
        request = webob.Request.blank('/v1.1/fake/images/detail')
641
646
        response = request.get_response(fakes.wsgi_app())
642
647
 
643
648
        response_dict = json.loads(response.body)
655
660
            'progress': 100,
656
661
            "links": [{
657
662
                "rel": "self",
658
 
                "href": "http://localhost/v1.1/images/123",
 
663
                "href": "http://localhost/v1.1/fake/images/123",
659
664
            },
660
665
            {
661
666
                "rel": "bookmark",
662
 
                "href": "http://localhost/images/123",
 
667
                "href": "http://localhost/fake/images/123",
663
668
            }],
664
669
        },
665
670
        {
686
691
            },
687
692
            "links": [{
688
693
                "rel": "self",
689
 
                "href": "http://localhost/v1.1/images/124",
 
694
                "href": "http://localhost/v1.1/fake/images/124",
690
695
            },
691
696
            {
692
697
                "rel": "bookmark",
693
 
                "href": "http://localhost/images/124",
 
698
                "href": "http://localhost/fake/images/124",
694
699
            }],
695
700
        },
696
701
        {
717
722
            },
718
723
            "links": [{
719
724
                "rel": "self",
720
 
                "href": "http://localhost/v1.1/images/125",
 
725
                "href": "http://localhost/v1.1/fake/images/125",
721
726
            },
722
727
            {
723
728
                "rel": "bookmark",
724
 
                "href": "http://localhost/images/125",
 
729
                "href": "http://localhost/fake/images/125",
725
730
            }],
726
731
        },
727
732
        {
748
753
            },
749
754
            "links": [{
750
755
                "rel": "self",
751
 
                "href": "http://localhost/v1.1/images/126",
 
756
                "href": "http://localhost/v1.1/fake/images/126",
752
757
            },
753
758
            {
754
759
                "rel": "bookmark",
755
 
                "href": "http://localhost/images/126",
 
760
                "href": "http://localhost/fake/images/126",
756
761
            }],
757
762
        },
758
763
        {
779
784
            },
780
785
            "links": [{
781
786
                "rel": "self",
782
 
                "href": "http://localhost/v1.1/images/127",
 
787
                "href": "http://localhost/v1.1/fake/images/127",
783
788
            },
784
789
            {
785
790
                "rel": "bookmark",
786
 
                "href": "http://localhost/images/127",
 
791
                "href": "http://localhost/fake/images/127",
787
792
            }],
788
793
        },
789
794
        {
796
801
            'progress': 100,
797
802
            "links": [{
798
803
                "rel": "self",
799
 
                "href": "http://localhost/v1.1/images/129",
 
804
                "href": "http://localhost/v1.1/fake/images/129",
800
805
            },
801
806
            {
802
807
                "rel": "bookmark",
803
 
                "href": "http://localhost/images/129",
 
808
                "href": "http://localhost/fake/images/129",
804
809
            }],
805
810
        },
806
811
        ]
809
814
 
810
815
    def test_image_filter_with_name(self):
811
816
        image_service = self.mox.CreateMockAnything()
812
 
        context = object()
 
817
        context = self._get_fake_context()
813
818
        filters = {'name': 'testname'}
814
819
        image_service.index(context, filters=filters).AndReturn([])
815
820
        self.mox.ReplayAll()
821
826
 
822
827
    def test_image_filter_with_status(self):
823
828
        image_service = self.mox.CreateMockAnything()
824
 
        context = object()
 
829
        context = self._get_fake_context()
825
830
        filters = {'status': 'ACTIVE'}
826
831
        image_service.index(context, filters=filters).AndReturn([])
827
832
        self.mox.ReplayAll()
833
838
 
834
839
    def test_image_filter_with_property(self):
835
840
        image_service = self.mox.CreateMockAnything()
836
 
        context = object()
 
841
        context = self._get_fake_context()
837
842
        filters = {'property-test': '3'}
838
843
        image_service.index(context, filters=filters).AndReturn([])
839
844
        self.mox.ReplayAll()
845
850
 
846
851
    def test_image_filter_server(self):
847
852
        image_service = self.mox.CreateMockAnything()
848
 
        context = object()
 
853
        context = self._get_fake_context()
849
854
        # 'server' should be converted to 'property-instance_ref'
850
855
        filters = {'property-instance_ref': 'http://localhost:8774/servers/12'}
851
856
        image_service.index(context, filters=filters).AndReturn([])
859
864
 
860
865
    def test_image_filter_changes_since(self):
861
866
        image_service = self.mox.CreateMockAnything()
862
 
        context = object()
 
867
        context = self._get_fake_context()
863
868
        filters = {'changes-since': '2011-01-24T17:08Z'}
864
869
        image_service.index(context, filters=filters).AndReturn([])
865
870
        self.mox.ReplayAll()
872
877
 
873
878
    def test_image_filter_with_type(self):
874
879
        image_service = self.mox.CreateMockAnything()
875
 
        context = object()
 
880
        context = self._get_fake_context()
876
881
        filters = {'property-image_type': 'BASE'}
877
882
        image_service.index(context, filters=filters).AndReturn([])
878
883
        self.mox.ReplayAll()
884
889
 
885
890
    def test_image_filter_not_supported(self):
886
891
        image_service = self.mox.CreateMockAnything()
887
 
        context = object()
 
892
        context = self._get_fake_context()
888
893
        filters = {'status': 'ACTIVE'}
889
894
        image_service.detail(context, filters=filters).AndReturn([])
890
895
        self.mox.ReplayAll()
897
902
 
898
903
    def test_image_no_filters(self):
899
904
        image_service = self.mox.CreateMockAnything()
900
 
        context = object()
 
905
        context = self._get_fake_context()
901
906
        filters = {}
902
907
        image_service.index(
903
908
            context, filters=filters).AndReturn([])
911
916
 
912
917
    def test_image_detail_filter_with_name(self):
913
918
        image_service = self.mox.CreateMockAnything()
914
 
        context = object()
 
919
        context = self._get_fake_context()
915
920
        filters = {'name': 'testname'}
916
921
        image_service.detail(context, filters=filters).AndReturn([])
917
922
        self.mox.ReplayAll()
918
 
        request = webob.Request.blank('/v1.1/images/detail?name=testname')
 
923
        request = webob.Request.blank('/v1.1/fake/images/detail?name=testname')
919
924
        request.environ['nova.context'] = context
920
925
        controller = images.ControllerV11(image_service=image_service)
921
926
        controller.detail(request)
923
928
 
924
929
    def test_image_detail_filter_with_status(self):
925
930
        image_service = self.mox.CreateMockAnything()
926
 
        context = object()
 
931
        context = self._get_fake_context()
927
932
        filters = {'status': 'ACTIVE'}
928
933
        image_service.detail(context, filters=filters).AndReturn([])
929
934
        self.mox.ReplayAll()
930
 
        request = webob.Request.blank('/v1.1/images/detail?status=ACTIVE')
 
935
        request = webob.Request.blank('/v1.1/fake/images/detail?status=ACTIVE')
931
936
        request.environ['nova.context'] = context
932
937
        controller = images.ControllerV11(image_service=image_service)
933
938
        controller.detail(request)
935
940
 
936
941
    def test_image_detail_filter_with_property(self):
937
942
        image_service = self.mox.CreateMockAnything()
938
 
        context = object()
 
943
        context = self._get_fake_context()
939
944
        filters = {'property-test': '3'}
940
945
        image_service.detail(context, filters=filters).AndReturn([])
941
946
        self.mox.ReplayAll()
942
 
        request = webob.Request.blank('/v1.1/images/detail?property-test=3')
 
947
        request = webob.Request.blank(
 
948
            '/v1.1/fake/images/detail?property-test=3')
943
949
        request.environ['nova.context'] = context
944
950
        controller = images.ControllerV11(image_service=image_service)
945
951
        controller.detail(request)
947
953
 
948
954
    def test_image_detail_filter_server(self):
949
955
        image_service = self.mox.CreateMockAnything()
950
 
        context = object()
 
956
        context = self._get_fake_context()
951
957
        # 'server' should be converted to 'property-instance_ref'
952
958
        filters = {'property-instance_ref': 'http://localhost:8774/servers/12'}
953
959
        image_service.index(context, filters=filters).AndReturn([])
954
960
        self.mox.ReplayAll()
955
 
        request = webob.Request.blank('/v1.1/images/detail?server='
 
961
        request = webob.Request.blank('/v1.1/fake/images/detail?server='
956
962
                                      'http://localhost:8774/servers/12')
957
963
        request.environ['nova.context'] = context
958
964
        controller = images.ControllerV11(image_service=image_service)
961
967
 
962
968
    def test_image_detail_filter_changes_since(self):
963
969
        image_service = self.mox.CreateMockAnything()
964
 
        context = object()
 
970
        context = self._get_fake_context()
965
971
        filters = {'changes-since': '2011-01-24T17:08Z'}
966
972
        image_service.index(context, filters=filters).AndReturn([])
967
973
        self.mox.ReplayAll()
968
 
        request = webob.Request.blank('/v1.1/images/detail?changes-since='
 
974
        request = webob.Request.blank('/v1.1/fake/images/detail?changes-since='
969
975
                                      '2011-01-24T17:08Z')
970
976
        request.environ['nova.context'] = context
971
977
        controller = images.ControllerV11(image_service=image_service)
974
980
 
975
981
    def test_image_detail_filter_with_type(self):
976
982
        image_service = self.mox.CreateMockAnything()
977
 
        context = object()
 
983
        context = self._get_fake_context()
978
984
        filters = {'property-image_type': 'BASE'}
979
985
        image_service.index(context, filters=filters).AndReturn([])
980
986
        self.mox.ReplayAll()
981
 
        request = webob.Request.blank('/v1.1/images/detail?type=BASE')
 
987
        request = webob.Request.blank('/v1.1/fake/images/detail?type=BASE')
982
988
        request.environ['nova.context'] = context
983
989
        controller = images.ControllerV11(image_service=image_service)
984
990
        controller.index(request)
986
992
 
987
993
    def test_image_detail_filter_not_supported(self):
988
994
        image_service = self.mox.CreateMockAnything()
989
 
        context = object()
 
995
        context = self._get_fake_context()
990
996
        filters = {'status': 'ACTIVE'}
991
997
        image_service.detail(context, filters=filters).AndReturn([])
992
998
        self.mox.ReplayAll()
993
 
        request = webob.Request.blank('/v1.1/images/detail?status=ACTIVE&'
 
999
        request = webob.Request.blank('/v1.1/fake/images/detail?status=ACTIVE&'
994
1000
                                      'UNSUPPORTEDFILTER=testname')
995
1001
        request.environ['nova.context'] = context
996
1002
        controller = images.ControllerV11(image_service=image_service)
999
1005
 
1000
1006
    def test_image_detail_no_filters(self):
1001
1007
        image_service = self.mox.CreateMockAnything()
1002
 
        context = object()
 
1008
        context = self._get_fake_context()
1003
1009
        filters = {}
1004
1010
        image_service.detail(context, filters=filters).AndReturn([])
1005
1011
        self.mox.ReplayAll()
1006
 
        request = webob.Request.blank('/v1.1/images/detail')
 
1012
        request = webob.Request.blank('/v1.1/fake/images/detail')
1007
1013
        request.environ['nova.context'] = context
1008
1014
        controller = images.ControllerV11(image_service=image_service)
1009
1015
        controller.detail(request)
1123
1129
    TIMESTAMP = "2010-10-11T10:30:22Z"
1124
1130
    SERVER_HREF = 'http://localhost/v1.1/servers/123'
1125
1131
    SERVER_BOOKMARK = 'http://localhost/servers/123'
1126
 
    IMAGE_HREF = 'http://localhost/v1.1/images/%s'
1127
 
    IMAGE_BOOKMARK = 'http://localhost/images/%s'
 
1132
    IMAGE_HREF = 'http://localhost/v1.1/fake/images/%s'
 
1133
    IMAGE_BOOKMARK = 'http://localhost/fake/images/%s'
1128
1134
 
1129
1135
    def test_show(self):
1130
1136
        serializer = images.ImageXMLSerializer()