Exemplo n.º 1
0
    def test_module_fail_connection_timeout(self, mock_bootstrap_init,
                                            mock_get, mock_post, mock_sleep):
        def mock_get_v1_cluster_me_version():
            return {"version": "5.0.2-p1-2130"}

        def mock_post_v1_exception():
            return APICallException(
                'Failed to establish a new connection: [Errno 111] Connection refused'
            )

        node_config = {}
        node_config['1'] = '10.255.1.10'

        set_module_args({
            'cluster_name': 'cluster_name',
            'admin_email': '*****@*****.**',
            'admin_password': '******',
            'node_ip': 'rubrikbootstrap.local',
            'node_config': node_config,
            'management_gateway': '10.255.1.1',
            'management_subnet_mask': '255.255.255.0',
            'username': '******',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'wait_for_completion': False
        })

        # Mock sleep function so test does not take too long to run
        mock_sleep.return_value = None
        mock_sleep.side_effect = None

        mock_bootstrap_init.return_value = None
        mock_bootstrap_init.ipv6_addr = 'ffd2::1'
        mock_bootstrap_init.ipv6_scope = '0'
        mock_bootstrap_init.node_ip = 'ffd2::1%0'

        mock_post.side_effect = mock_post_v1_exception()

        mock_get.return_value = mock_get_v1_cluster_me_version()

        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_bootstrap.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            'Unable to establish a connection to the Rubrik cluster.')
Exemplo n.º 2
0
    def test_module_bootstrap_idempotency(self, mock_bootstrap_init, mock_post,
                                          mock_get):
        def mock_get_v1_cluster_me_version():
            return {"version": "5.0.2-p1-2130"}

        def mock_post_v1_exception():
            return APICallException(
                'Cannot bootstrap from an already bootstrapped node')

        node_config = {}
        node_config['1'] = '10.255.1.10'

        set_module_args({
            'cluster_name': 'cluster_name',
            'admin_email': '*****@*****.**',
            'admin_password': '******',
            'node_ip': 'rubrikbootstrap.local',
            'node_config': node_config,
            'management_gateway': '10.255.1.1',
            'management_subnet_mask': '255.255.255.0',
            'username': '******',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'wait_for_completion': False
        })

        mock_bootstrap_init.return_value = None
        mock_bootstrap_init.ipv6_addr = 'ffd2::1'
        mock_bootstrap_init.ipv6_scope = '0'
        mock_bootstrap_init.node_ip = 'ffd2::1%0'

        mock_post.side_effect = mock_post_v1_exception()

        mock_get.return_value = mock_get_v1_cluster_me_version()

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_bootstrap.main()

        self.assertEqual(result.exception.args[0]['changed'], False)
        self.assertEqual(
            result.exception.args[0]['response'],
            'No change required. The Rubrik cluster is already bootstrapped.')
Exemplo n.º 3
0
    def test_module_fail_with_malformed_node_config(self):
        set_module_args({
            'cluster_name': 'cluster_name',
            'admin_email': '*****@*****.**',
            'admin_password': '******',
            'node_ip': 'rubrikbootstrap.local',
            'node_config': 'foo',
            'management_gateway': '10.255.1.1',
            'management_subnet_mask': '255.255.255.0',
            'username': '******',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_bootstrap.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            "argument node_config is of type <class 'str'> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value"
        )
Exemplo n.º 4
0
    def test_module_bootstrap_node_no_wait(self, mock_bootstrap_init, mock_get,
                                           mock_post):
        def mock_get_v1_cluster_me_version():
            return {"version": "5.0.2-p1-2130"}

        def mock_post_v1_bootstrap():
            return {'id': 0, 'status': 'IN_PROGRESS'}

        node_config = {}
        node_config['1'] = '10.255.1.10'

        set_module_args({
            'cluster_name': 'cluster_name',
            'admin_email': '*****@*****.**',
            'admin_password': '******',
            'node_ip': 'rubrikbootstrap.local',
            'node_config': node_config,
            'management_gateway': '10.255.1.1',
            'management_subnet_mask': '255.255.255.0',
            'username': '******',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'wait_for_completion': False
        })

        mock_bootstrap_init.return_value = None
        mock_bootstrap_init.ipv6_addr = 'ffd2::1'
        mock_bootstrap_init.ipv6_scope = '0'
        mock_bootstrap_init.node_ip = 'ffd2::1%0'

        mock_post.return_value = mock_post_v1_bootstrap()

        mock_get.return_value = mock_get_v1_cluster_me_version()

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_bootstrap.main()

        self.assertEqual(result.exception.args[0]['changed'], False)
        self.assertEqual(result.exception.args[0]['response']['status'],
                         'IN_PROGRESS')
Exemplo n.º 5
0
    def test_module_fail_resolution_failure(self, mock_post, mock_getaddrinfo,
                                            mock_get):
        def mock_get_v1_cluster_me_version():
            return {"version": "5.0.2-p1-2130"}

        def mock_getaddrinfo_failure():
            return gaierror(
                'Could not resolve link-local IPv6 address for cluster.')

        node_config = {}
        node_config['1'] = 'badhost.local'

        set_module_args({
            'cluster_name': 'cluster_name',
            'admin_email': '*****@*****.**',
            'admin_password': '******',
            'node_ip': 'rubrikbootstrap.local',
            'node_config': node_config,
            'management_gateway': '10.255.1.1',
            'management_subnet_mask': '255.255.255.0',
            'username': '******',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
        })

        mock_getaddrinfo.side_effect = mock_getaddrinfo_failure()

        mock_get.return_value = mock_get_v1_cluster_me_version()

        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_bootstrap.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            'Error: Could not resolve address for cluster, or invalid IP/address supplied'
        )
Exemplo n.º 6
0
 def test_module_fail_when_required_args_missing(self):
     with self.assertRaises(AnsibleFailJson):
         set_module_args({})
         rubrik_bootstrap.main()
Exemplo n.º 7
0
    def test_module_bootstrap_node_wait_for_completion(self,
                                                       mock_bootstrap_init,
                                                       mock_get, mock_post,
                                                       mock_sleep):
        def mock_get_v1_cluster_me_version():
            return {"version": "5.0.2-p1-2130"}

        def mock_post_v1_bootstrap():
            return {'id': 0, 'status': 'IN_PROGRESS'}

        def mock_get_v1_bootstrap_status_1():
            return {
                'status': 'IN_PROGRESS',
                'message': '',
                'ipConfig': 'SUCCESS',
                'cassandraSetup': 'SUCCESS',
                'installSchema': 'SUCCESS',
                'startServices': 'SUCCESS',
                'ipmiConfig': 'SUCCESS',
                'configAdminUser': '******',
                'resetNodes': 'IN_PROGRESS',
                'setupDisks': 'SUCCESS',
                'setupEncryptionAtRest': 'SUCCESS',
                'setupOsAndMetadataPartitions': 'SUCCESS',
                'createTopLevelFilesystemDirs': 'SUCCESS',
                'setupLoopDevices': 'SUCCESS',
                'cockroachDbSetup': 'SUCCESS'
            }

        def mock_get_v1_bootstrap_status_2():
            return {
                'status': 'SUCCESS',
                'message': '',
                'ipConfig': 'SUCCESS',
                'cassandraSetup': 'SUCCESS',
                'installSchema': 'SUCCESS',
                'startServices': 'SUCCESS',
                'ipmiConfig': 'SUCCESS',
                'configAdminUser': '******',
                'resetNodes': 'SUCCESS',
                'setupDisks': 'SUCCESS',
                'setupEncryptionAtRest': 'SUCCESS',
                'setupOsAndMetadataPartitions': 'SUCCESS',
                'createTopLevelFilesystemDirs': 'SUCCESS',
                'setupLoopDevices': 'SUCCESS',
                'cockroachDbSetup': 'SUCCESS'
            }

        node_config = {}
        node_config['1'] = '10.255.1.10'

        set_module_args({
            'cluster_name': 'cluster_name',
            'admin_email': '*****@*****.**',
            'admin_password': '******',
            'node_ip': 'rubrikbootstrap.local',
            'node_config': node_config,
            'management_gateway': '10.255.1.1',
            'management_subnet_mask': '255.255.255.0',
            'username': '******',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP',
            'timeout': 1,
            'wait_for_completion': True
        })

        # Mock sleep function so test does not take 30 seconds to run
        mock_sleep.return_value = None

        mock_bootstrap_init.return_value = None
        mock_bootstrap_init.ipv6_addr = 'ffd2::1'
        mock_bootstrap_init.ipv6_scope = '0'
        mock_bootstrap_init.node_ip = 'ffd2::1%0'

        mock_post.return_value = mock_post_v1_bootstrap()

        mock_get.side_effect = [
            mock_get_v1_cluster_me_version(),
            mock_get_v1_bootstrap_status_1(),
            mock_get_v1_bootstrap_status_2()
        ]

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_bootstrap.main()

        self.assertEqual(result.exception.args[0]['changed'], False)
        self.assertEqual(result.exception.args[0]['response']['status'],
                         'SUCCESS')