Пример #1
0
 def statistic_snapshot_create_error(self, req, start=None, end=None):
     """
     list all failed created images,
     then statistic for operations.
     """
     success, error = self._statistic_snapshot_operation(req, start, end)
     error = list_filter.filter_snapshot_error(req, error)
     error = list_sort.sort_snapshot_error(req, error)
     ret = {"ErrorSnapshotOperation": len(error), "FaultList": error}
     if start is not None:
         ret.update(start=start)
     if end is not None:
         ret.update(end=end)
     return ret
Пример #2
0
    def test_sort_snapshot_error(self):
        def generate_snapshot_error(**kwargs):
            instance_error = {
                     "owner": "abcd",
                     "name": "test",
                     "id": "d39ead1a-9d68-4e44-9cbd-d42b86030d34",
                     "created": "2013-01-01 00:00:00",
                     "desc": "NoValidHost"
                     }
            instance_error.update(**kwargs)
            return instance_error

        snapshot_error1 = generate_snapshot_error(owner="ownerA",
                                                  name="sg1",
                                                  desc="Not Found.")
        snapshot_error2 = generate_snapshot_error(owner="admin",
                                                  name="ubuntu",
                                                  id="40f7f068-8274-4167-"
                                                       "943c-1d19b1efc307",
                                                  created="2013-02-03 "
                                                          "10:00:00")
        snapshot_error3 = generate_snapshot_error(owner="opt",
                                                  name="sg2",
                                                  id="f8d4690c-71cc-4fe9-"
                                                       "a347-950effa1ad25",
                                                  created="2013-02-03 "
                                                          "09:00:00",
                                                  desc="")
        snapshot_errors = [snapshot_error1, snapshot_error2, snapshot_error3]

        req = webob.Request.blank(
                '/sort?umbrella_sort_key=tenantid')
        result = list_sort.sort_snapshot_error(req, snapshot_errors)
        expected = [snapshot_error2, snapshot_error3, snapshot_error1]
        self.assertEqual(result, expected)

        req = webob.Request.blank(
                '/sort?umbrella_sort_key=name')
        result = list_sort.sort_snapshot_error(req, snapshot_errors)
        expected = [snapshot_error1, snapshot_error3, snapshot_error2]
        self.assertEqual(result, expected)

        req = webob.Request.blank(
                '/sort?umbrella_sort_key=id')
        result = list_sort.sort_snapshot_error(req, snapshot_errors)
        expected = [snapshot_error2, snapshot_error1, snapshot_error3]
        self.assertEqual(result, expected)

        req = webob.Request.blank(
                '/sort?umbrella_sort_key=created')
        result = list_sort.sort_snapshot_error(req, snapshot_errors)
        expected = [snapshot_error1, snapshot_error3, snapshot_error2]
        self.assertEqual(result, expected)

        req = webob.Request.blank(
                '/sort?umbrella_sort_key=desc')
        result = list_sort.sort_snapshot_error(req, snapshot_errors)
        expected = [snapshot_error3, snapshot_error1, snapshot_error2]
        self.assertEqual(result, expected)

        req = webob.Request.blank(
                '/sort?umbrella_sort_key=desc&umbrella_sort_dir=desc')
        result = list_sort.sort_snapshot_error(req, snapshot_errors)
        expected = [snapshot_error2, snapshot_error1, snapshot_error3]
        self.assertEqual(result, expected)