Ejemplo n.º 1
0
    def setUp(self):

        super(TestAvailableJobs, self).setUp()

        from chroma_core.services.job_scheduler.job_scheduler import JobScheduler

        from tests.unit.chroma_core.helpers import load_default_profile

        load_default_profile()

        self.JobScheduler = JobScheduler
        self.js = JobScheduler()

        # Create object before ObjectCache init, so they are in the cache.
        self.host = synthetic_host()

        (mgt, fs, mdt, ost) = create_simple_fs()

        self.mgs = mgt
        self.fs = fs
        self.mdt = mdt
        self.ost = ost

        # If you create object after init of this case, they will not be in it.
        ObjectCache.getInstance()
    def setUp(self):
        super(TestTargetTransitions, self).setUp()

        (mgt, fs, mdt, ost) = create_simple_fs()
        self.mgt = mgt
        self.assertEqual(
            ManagedMgs.objects.get(pk=self.mgt.pk).state, "unmounted")
    def setUp(self):
        super(TestStateManager, self).setUp()
        (mgt, fs, mdt, ost) = create_simple_fs()
        self.mgt = mgt
        self.fs = fs

        self.lnet_configuration = self.host.lnet_configuration
        self._completion_hook_count = 0
        self.job_scheduler.add_completion_hook(self._completion_hook)
Ejemplo n.º 4
0
    def test_set_state_full(self):
        """Test operations using fully populated PUTs"""
        (mgt, fs, mdt, ost) = create_simple_fs()
        self.fs = fs

        fs_uri = "/api/filesystem/%s/" % self.fs.id
        with mock.patch("chroma_core.models.Command.set_state",
                        mock.Mock(return_value=None)):
            self.api_set_state_full(fs_uri, "stopped")
            Command.set_state.assert_called_once()
Ejemplo n.º 5
0
    def test_set_state_partial(self):
        """Test operations using partial PUT containing only the state attribute, as used in Chroma 1.0.0.0 GUI"""
        (mgt, fs, mdt, ost) = create_simple_fs()
        self.fs = fs

        fs_uri = "/api/filesystem/%s/" % self.fs.id
        with mock.patch("chroma_core.models.Command.set_state",
                        mock.Mock(return_value=None)):
            self.api_set_state_partial(fs_uri, "stopped")
            Command.set_state.assert_called_once()
Ejemplo n.º 6
0
    def create_simple_filesystem(self, start=True):
        (mgt, fs, mdt, ost) = create_simple_fs()

        self.fs = fs
        self.mgt = mgt
        self.mdt = mdt
        self.ost = ost

        if start:
            self.fs = self.set_and_assert_state(self.fs, "available")
Ejemplo n.º 7
0
    def test_set_state_full(self):
        """Test operations using a fully populated PUT"""
        host = synthetic_host("myserver")
        (mgt, fs, mdt, ost) = create_simple_fs()
        self.mgt = mgt

        mgt_uri = "/api/target/%s/" % self.mgt.id
        with mock.patch("chroma_core.models.Command.set_state",
                        mock.Mock(return_value=None)):
            self.api_set_state_full(mgt_uri, "unmounted")
            Command.set_state.assert_called_once()
Ejemplo n.º 8
0
    def test_set_state_partial(self):
        """Test operations using partial PUT containing only the state attribute, as used in Chroma 1.0.0.0 GUI"""
        host = synthetic_host("myserver")
        (mgt, fs, mdt, ost) = create_simple_fs()
        self.mgt = mgt

        mgt_uri = "/api/target/%s/" % self.mgt.id
        with mock.patch("chroma_core.models.Command.set_state",
                        mock.Mock(return_value=None)):
            self.api_set_state_partial(mgt_uri, "unmounted")
            Command.set_state.assert_called_once()
Ejemplo n.º 9
0
    def setUp(self):
        super(TestNidStrings, self).setUp()

        # If the test that just ran imported storage_plugin_manager, it will
        # have instantiated its singleton, and created some DB records.
        # Django TestCase rolls back the database, so make sure that we
        # also roll back (reset) this singleton.
        import chroma_core.lib.storage_plugin.manager

        chroma_core.lib.storage_plugin.manager.storage_plugin_manager = (
            chroma_core.lib.storage_plugin.manager.StoragePluginManager())

        load_default_profile()

        def get_targets_fn():
            ids = [x.id for x in ManagedHost.objects.all()]
            host_id = ids[0]

            return [
                {
                    "name": "MGS",
                    "active_host_id": host_id,
                    "host_ids": [ids[0]]
                },
                {
                    "name": "MGS_ha",
                    "active_host_id": host_id,
                    "host_ids": [ids[0], ids[1]]
                },
            ]

        self.get_targets_mock = mock.MagicMock(side_effect=get_targets_fn)
        mock.patch("chroma_core.lib.graphql.get_targets",
                   new=self.get_targets_mock).start()

        (mgt, fs, mdt, ost) = create_simple_fs()
        self.mgt = mgt
        self.fs = fs
Ejemplo n.º 10
0
 def test_spider(self):
     self.spider_api()
     create_simple_fs()
     self.spider_api()
    def test_removals(self):
        """Test that after objects are removed all GETs still work

        The idea is to go through a add hosts, create FS, remove FS, remove hosts
        cycle and then do a spider of the API to ensure that there aren't any
        exceptions rendering things (e.g. due to trying to dereference removed
        things incorrectly)"""

        host = synthetic_host("myserver")
        create_simple_fs()

        # Create a command/job/step result referencing the host
        command = Command.objects.create(message="test command",
                                         complete=True,
                                         errored=True)
        job = StopLNetJob.objects.create(
            lnet_configuration=host.lnet_configuration,
            state="complete",
            errored=True)
        command.jobs.add(job)
        step_klass, args = job.get_steps()[0]
        StepResult.objects.create(job=job,
                                  backtrace="an error",
                                  step_klass=step_klass,
                                  args=args,
                                  step_index=0,
                                  step_count=1,
                                  state="failed")

        # There will now be an CommandErroredAlert because the command above failed.
        alerts = self.deserialize(
            self.api_client.get("/api/alert/"))["objects"]
        self.assertEqual(len(alerts), 1)
        self.assertEqual(alerts[0]["alert_type"], "CommandErroredAlert")

        # Now create an alert/event referencing the host
        HostOfflineAlert.notify(host, True)
        alerts = self.deserialize(
            self.api_client.get("/api/alert/", data={"active":
                                                     True}))["objects"]
        self.assertEqual(len(alerts), 1)
        self.assertEqual(alerts[0]["alert_type"], "HostOfflineAlert")

        # Double check that is 2 alerts in total.
        alerts = self.deserialize(
            self.api_client.get("/api/alert/"))["objects"]
        self.assertEqual(len(alerts), 2)

        # Cause JobScheduler() to delete the objects, check the objects are gone in the API
        # and the API can still be spidered cleanly
        job = ForceRemoveHostJob(host=host)
        for step_klass, args in job.get_steps():
            step_klass(job, args, None, None, None).run(args)

        # Check everything is gone
        self.assertEqual(ManagedTarget.objects.count(), 0)
        self.assertEqual(ManagedHost.objects.count(), 0)
        self.assertEqual(Volume.objects.count(), 0)
        self.assertEqual(VolumeNode.objects.count(), 0)
        self.assertListEqual(
            self.deserialize(
                self.api_client.get("/api/alert/?active=true"))["objects"], [])
        self.assertListEqual(
            self.deserialize(self.api_client.get("/api/volume/"))["objects"],
            [])
        self.assertListEqual(
            self.deserialize(
                self.api_client.get("/api/volume_node/"))["objects"], [])
        self.assertListEqual(
            self.deserialize(self.api_client.get("/api/target/"))["objects"],
            [])
        self.assertListEqual(
            self.deserialize(self.api_client.get("/api/host/"))["objects"], [])
        self.assertListEqual(
            self.deserialize(
                self.api_client.get("/api/filesystem/"))["objects"], [])

        # Check resources still render without exceptions
        self.spider_api()