Example #1
0
 def get_context_data(self, request):
     context = {}
     environment_id = self.tab_group.kwargs['environment_id']
     context['environment_id'] = environment_id
     self.tab_group.load_tab_data()
     d3_data = topology.render_d3_data(request, self.tab_group._data['env'])
     #d3_data = api.load_environment_data(self.request, environment_id)
     context['d3_data'] = d3_data
     return context
Example #2
0
def load_environment_data(request, environment_id):
    environment = environment_get(request, environment_id)
    return topology.render_d3_data(request, environment)
Example #3
0
def load_environment_data(request, environment_id):
    environment = environment_get(request, environment_id)
    return topology.render_d3_data(request, environment)
Example #4
0
 def test_render_d3_data_without_environment(self):
     self.assertIsNone(topology.render_d3_data(self.request, None))
     # Test without environment.services
     mock_env = mock.Mock(services=None)
     self.assertIsNone(topology.render_d3_data(self.request, mock_env))
Example #5
0
    def test_render_d3_data(self, mock_pkg_cli, mock_loader):
        mock_pkg_cli.app_by_fqn.return_value = None
        mock_loader.render_to_string.return_value = 'test_env_info'

        fake_services = [
            {
                '?': {
                    'id': 'test_service_id',
                    'status': consts.STATUS_ID_READY,
                    'type': 'io.murano.resources.foo',
                },
                'name': 'foo',
                'instance': {
                    '?': {
                        'id': 'test_instance_id',
                        'type': 'io.murano.resources.bar',
                    },
                    'assignFloatingIp': True,
                    'extra': [{'name': 'bar'}],
                    'name': 'bar',
                    'ipAddresses': ['127.0.0.1']
                }
            },
            {
                '?': {
                    'id': 'test_alt_service_id',
                    'status': consts.STATUS_ID_PENDING,
                    'type': 'test_service_type',
                },
                'name': 'baz',
                'instance': {
                    '?': {
                        'id': 'test_alt_instance_id',
                        'type': 'test_instance_type',
                    },
                    'assignFloatingIp': False,
                    'name': 'qux',
                    'required_by': 'test_service_id'
                },
            }
        ]

        mock_environment = mock.Mock(
            id='test_env_id',
            status=consts.STATUS_ID_READY,
            services=fake_services)
        mock_environment.configure_mock(name='test_env_name')

        expected_env = {
            'id': 'test_env_id',
            'in_progress': False,
            'info_box': 'test_env_info',
            'name': 'test_env_name',
            'status': 'Deployed'
        }

        expected_node_ids = (
            'External_Network', 'test_service_id', 'test_instance_id',
            'test_alt_service_id', 'test_alt_instance_id')

        result = topology.render_d3_data(self.request, mock_environment)
        result = json.loads(result)
        self.assertIsInstance(result, dict)
        self.assertIn('environment', result)
        self.assertIn('nodes', result)

        for key, val in expected_env.items():
            self.assertEqual(val, result['environment'][key])

        for node_id in expected_node_ids:
            self.assertIn(node_id,
                          [node['id'] for node in result['nodes']])
 def test_render_d3_data_without_environment(self):
     self.assertIsNone(topology.render_d3_data(self.request, None))
     # Test without environment.services
     mock_env = mock.Mock(services=None)
     self.assertIsNone(topology.render_d3_data(self.request, mock_env))
    def test_render_d3_data(self, mock_pkg_cli, mock_loader):
        mock_pkg_cli.app_by_fqn.return_value = None
        mock_loader.render_to_string.return_value = 'test_env_info'

        fake_services = [
            {
                '?': {
                    'id': 'test_service_id',
                    'status': consts.STATUS_ID_READY,
                    'type': 'io.murano.resources.foo',
                },
                'name': 'foo',
                'instance': {
                    '?': {
                        'id': 'test_instance_id',
                        'type': 'io.murano.resources.bar',
                    },
                    'assignFloatingIp': True,
                    'extra': [{'name': 'bar'}],
                    'name': 'bar',
                    'ipAddresses': ['127.0.0.1']
                }
            },
            {
                '?': {
                    'id': 'test_alt_service_id',
                    'status': consts.STATUS_ID_PENDING,
                    'type': 'test_service_type',
                },
                'name': 'baz',
                'instance': {
                    '?': {
                        'id': 'test_alt_instance_id',
                        'type': 'test_instance_type',
                    },
                    'assignFloatingIp': False,
                    'name': 'qux',
                    'required_by': 'test_service_id'
                },
            }
        ]

        mock_environment = mock.Mock(
            id='test_env_id',
            status=consts.STATUS_ID_READY,
            services=fake_services)
        mock_environment.configure_mock(name='test_env_name')

        expected_env = {
            'id': 'test_env_id',
            'in_progress': False,
            'info_box': 'test_env_info',
            'name': 'test_env_name',
            'status': 'Deployed'
        }

        expected_node_ids = (
            'External_Network', 'test_service_id', 'test_instance_id',
            'test_alt_service_id', 'test_alt_instance_id')

        result = topology.render_d3_data(self.request, mock_environment)
        result = json.loads(result)
        self.assertIsInstance(result, dict)
        self.assertIn('environment', result)
        self.assertIn('nodes', result)

        for key, val in expected_env.items():
            self.assertEqual(val, result['environment'][key])

        for node_id in expected_node_ids:
            self.assertIn(node_id,
                          [node['id'] for node in result['nodes']])