def test_kube_host_upgrade_list_multiple(self):
        self.make_env()
        self.kube_host_upgrade_manager_list_result = [
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE, True),
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE_2, True),
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE_3, True),
        ]
        self.ihost_manager_list_result = [
            ihost(None, FAKE_IHOST, True),
            ihost(None, FAKE_IHOST_2, True),
            ihost(None, FAKE_IHOST_3, True),
        ]

        # Use --nowrap to prevent failure when test run with small terminal
        results = self.shell("kube-host-upgrade-list --nowrap")

        for fake_ihost in [FAKE_IHOST, FAKE_IHOST_2, FAKE_IHOST_3]:
            self.assertIn(str(fake_ihost['id']), results)
            self.assertIn(str(fake_ihost['hostname']), results)
            self.assertIn(str(fake_ihost['personality']), results)

        for fake_kube_host_upgrade in [
                FAKE_KUBE_HOST_UPGRADE, FAKE_KUBE_HOST_UPGRADE_2,
                FAKE_KUBE_HOST_UPGRADE_3
        ]:
            self.assertIn(str(fake_kube_host_upgrade['target_version']),
                          results)
            self.assertIn(str(fake_kube_host_upgrade['control_plane_version']),
                          results)
            self.assertIn(str(fake_kube_host_upgrade['kubelet_version']),
                          results)
            self.assertIn(str(fake_kube_host_upgrade['status']), results)
    def setUp(self):
        super(HostTest, self).setUp()

        # Mock the client
        p = mock.patch('cgtsclient.client._get_endpoint')
        self.mock_cgtsclient_client_get_endpoint = p.start()
        self.mock_cgtsclient_client_get_endpoint.return_value = \
            'http://fakelocalhost:6385/v1'
        self.addCleanup(p.stop)
        p = mock.patch('cgtsclient.client._get_ksclient')
        self.mock_cgtsclient_client_get_ksclient = p.start()
        self.addCleanup(p.stop)

        # Mock the KubeHostUpgradeManager
        self.kube_host_upgrade_manager_list_result = [
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE, True)
        ]

        def mock_kube_host_upgrade_manager_list(obj):
            return self.kube_host_upgrade_manager_list_result

        self.mocked_kube_host_upgrade_manager_list = mock.patch(
            'cgtsclient.v1.kube_host_upgrade.KubeHostUpgradeManager.list',
            mock_kube_host_upgrade_manager_list)
        self.mocked_kube_host_upgrade_manager_list.start()
        self.addCleanup(self.mocked_kube_host_upgrade_manager_list.stop)

        # Mock the ihostManager
        self.ihost_manager_list_result = [ihost(None, FAKE_IHOST, True)]

        def mock_ihost_manager_list(obj):
            return self.ihost_manager_list_result

        self.mocked_ihost_manager_list = mock.patch(
            'cgtsclient.v1.ihost.ihostManager.list', mock_ihost_manager_list)
        self.mocked_ihost_manager_list.start()
        self.addCleanup(self.mocked_ihost_manager_list.stop)

        self.ihost_manager_kube_upgrade_control_plane_result = \
            [ihost(None, FAKE_IHOST, True)]

        def mock_ihost_manager_kube_upgrade_control_plane(obj, hostid, force):
            return self.ihost_manager_kube_upgrade_control_plane_result

        self.mocked_ihost_manager_kube_upgrade_control_plane = mock.patch(
            'cgtsclient.v1.ihost.ihostManager.kube_upgrade_control_plane',
            mock_ihost_manager_kube_upgrade_control_plane)
        self.mocked_ihost_manager_kube_upgrade_control_plane.start()
        self.addCleanup(
            self.mocked_ihost_manager_kube_upgrade_control_plane.stop)

        def mock_ihost_manager_kube_upgrade_kubelet(obj, hostid, force):
            return self.ihost_manager_kube_upgrade_kubelet_result

        self.mocked_ihost_manager_kube_upgrade_kubelet = mock.patch(
            'cgtsclient.v1.ihost.ihostManager.kube_upgrade_kubelet',
            mock_ihost_manager_kube_upgrade_kubelet)
        self.mocked_ihost_manager_kube_upgrade_kubelet.start()
        self.addCleanup(self.mocked_ihost_manager_kube_upgrade_kubelet.stop)
예제 #3
0
 def test_host_list(self, mock_get_endpoint, mock_get_client, mock_list):
     # This unit test mocks returning a single controller-0 host through host-list
     mock_get_endpoint.return_value = 'http://fakelocalhost:6385/v1'
     fake_controller = {'id': '0',
                        'hostname': 'controller-0',
                        'personality': 'controller',
                        'administrative': 'unlocked',
                        'operational': 'enabled',
                        'availability': 'available'}
     mock_list.return_value = [ihost(None, fake_controller, True)]
     self.make_env()
     host_results = self.shell("host-list")
     self.assertIn('controller-0', host_results)
     self.assertNotIn('controller-1', host_results)
    def test_kube_host_upgrade_kubelet(self):
        self.make_env()
        self.kube_host_upgrade_manager_list_result = [
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE, True),
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE_2, True),
            KubeHostUpgrade(None, FAKE_KUBE_HOST_UPGRADE_3, True),
        ]
        self.ihost_manager_kube_upgrade_kubelet_result = \
            ihost(None, FAKE_IHOST_2, True)

        results = self.shell("kube-host-upgrade controller-1 kubelet")

        self.assertIn(str(FAKE_IHOST_2['id']), results)
        self.assertIn(str(FAKE_IHOST_2['hostname']), results)
        self.assertIn(str(FAKE_IHOST_2['personality']), results)

        self.assertIn(str(FAKE_KUBE_HOST_UPGRADE_2['target_version']), results)
        self.assertIn(str(FAKE_KUBE_HOST_UPGRADE_2['control_plane_version']),
                      results)
        self.assertIn(str(FAKE_KUBE_HOST_UPGRADE_2['kubelet_version']),
                      results)
        self.assertIn(str(FAKE_KUBE_HOST_UPGRADE_2['status']), results)