]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/hosts/hosts.component.spec.ts
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / hosts / hosts.component.spec.ts
index 82e85965b39a8a34ad109719ee46db9457d42c85..c92188ed054114173bd6733ec855d6cdea4fce55 100644 (file)
@@ -24,11 +24,26 @@ import {
 } from '~/testing/unit-test-helper';
 import { HostsComponent } from './hosts.component';
 
+class MockShowForceMaintenanceModal {
+  showModal = false;
+  showModalDialog(msg: string) {
+    if (
+      msg.includes('WARNING') &&
+      !msg.includes('It is NOT safe to stop') &&
+      !msg.includes('ALERT') &&
+      !msg.includes('unable to stop')
+    ) {
+      this.showModal = true;
+    }
+  }
+}
+
 describe('HostsComponent', () => {
   let component: HostsComponent;
   let fixture: ComponentFixture<HostsComponent>;
   let hostListSpy: jasmine.Spy;
   let orchService: OrchestratorService;
+  let showForceMaintenanceModal: MockShowForceMaintenanceModal;
 
   const fakeAuthStorageService = {
     getPermissions: () => {
@@ -54,6 +69,7 @@ describe('HostsComponent', () => {
   });
 
   beforeEach(() => {
+    showForceMaintenanceModal = new MockShowForceMaintenanceModal();
     fixture = TestBed.createComponent(HostsComponent);
     component = fixture.componentInstance;
     hostListSpy = spyOn(TestBed.inject(HostService), 'list');
@@ -102,6 +118,37 @@ describe('HostsComponent', () => {
     });
   });
 
+  it('should show force maintenance modal when it is safe to stop host', () => {
+    const errorMsg = `WARNING: Stopping 1 out of 1 daemons in Grafana service.
+                    Service will not be operational with no daemons left. At
+                    least 1 daemon must be running to guarantee service.`;
+    showForceMaintenanceModal.showModalDialog(errorMsg);
+    expect(showForceMaintenanceModal.showModal).toBeTruthy();
+  });
+
+  it('should not show force maintenance modal when error is an ALERT', () => {
+    const errorMsg = `ALERT: Cannot stop active Mgr daemon, Please switch active Mgrs
+                    with 'ceph mgr fail ceph-node-00'`;
+    showForceMaintenanceModal.showModalDialog(errorMsg);
+    expect(showForceMaintenanceModal.showModal).toBeFalsy();
+  });
+
+  it('should not show force maintenance modal when it is not safe to stop host', () => {
+    const errorMsg = `WARNING: Stopping 1 out of 1 daemons in Grafana service.
+                    Service will not be operational with no daemons left. At
+                    least 1 daemon must be running to guarantee service.
+                    It is NOT safe to stop ['mon.ceph-node-00']: not enough
+                    monitors would be available (ceph-node-02) after stopping mons`;
+    showForceMaintenanceModal.showModalDialog(errorMsg);
+    expect(showForceMaintenanceModal.showModal).toBeFalsy();
+  });
+
+  it('should not show force maintenance modal when it is unable to stop host', () => {
+    const errorMsg = 'unable to stop osd.0 because of some unknown reason';
+    showForceMaintenanceModal.showModalDialog(errorMsg);
+    expect(showForceMaintenanceModal.showModal).toBeFalsy();
+  });
+
   describe('table actions', () => {
     const fakeHosts = require('./fixtures/host_list_response.json');