Esempio n. 1
0
 def setUp(self):
     super(TestPackageMatcher, self).setUp()
     logsetting.init()
     file_matchers = [
         FileMatcher(
             min_progress=0.6,
             max_progress=0.9,
             filename='test_log',
             line_matchers={
                 'start': LineMatcher(
                     pattern=r'',
                     severity='',
                 )
             }
         )
     ]
     self.item_matcher = adapter_matcher.AdapterItemMatcher(file_matchers)
     self.file_reader_factory = FileReaderFactory(
         logdir=os.path.dirname(
             os.path.abspath(__file__)) + '/data'
     )
     self.package_matcher = adapter_matcher.PackageMatcher(
         package_installer_name='chef',
         adapter_pattern=r'openstack',
         item_matcher=self.item_matcher,
         file_reader_factory=self.file_reader_factory
     )
    def test_both_unmatch(self):
        test_both_unmatch = {
            'os_matcher': {
                'os_installer_name': 'cobbler',
                'os_pattern': 'Ubuntu*',
                'item_matcher': self.os_item_matcher,
                'min_progress': 0.0,
                'max_progress': 0.6
            },
            'package_matcher': {
                'package_installer_name': 'chef',
                'target_system': 'hadoop',
                'item_matcher': self.package_item_matcher,
                'min_progress': 0.6,
                'max_progress': 1.0
            }
        }
        os_matcher = adapter_matcher.OSMatcher(
            **test_both_unmatch['os_matcher'])
        package_matcher = adapter_matcher.PackageMatcher(
            **test_both_unmatch['package_matcher'])
        matcher = adapter_matcher.AdapterMatcher(
            os_matcher, package_matcher)

        self.assertFalse(
            matcher.match(
                'cobbler', 'CentOS6.4',
                'chef', 'openstack'))
 def test_both_unmatch(self):
     test_both_unmatch = {
         'package_installer_name': 'puppet',
         'target_system': 'hadoop',
         'item_matcher': self.item_matcher,
         'min_progress': 0.6,
         'max_progress': 1.0,
     }
     matcher = adapter_matcher.PackageMatcher(
         **test_both_unmatch)
     self.assertFalse(matcher.match(
         'chef',
         'openstack'))
 def test_match(self):
     test_match = {
         'package_installer_name': 'chef',
         'target_system': 'openstack',
         'item_matcher': self.item_matcher,
         'min_progress': 0.6,
         'max_progress': 1.0,
     }
     matcher = adapter_matcher.PackageMatcher(
         **test_match)
     self.assertTrue(matcher.match(
         'chef',
         'openstack'))
    def test_update_progress(self):
        config = {
            'ADAPTERS': [
                {
                    'name': 'CentOS_openstack',
                    'os': 'CentOS',
                    'target_system': 'openstack',
                },
            ],
            'ROLES': [
                {
                    'name': 'os-single-controller',
                    'target_system': 'openstack',
                },
                {
                    'name': 'os-network',
                    'target_system': 'openstack',
                },
                {
                    'name': 'os-compute',
                    'target_system': 'openstack',
                },
            ],
            'SWITCHES': [
                {
                    'ip': '1.2.3.4',
                    'vendor': 'huawei',
                    'credential': {
                        'version': 'v2c',
                        'comunity': 'public',
                    }
                },
            ],
            'MACHINES_BY_SWITCH': {
                '1.2.3.4': [
                    {
                        'mac': '00:00:01:02:03:04',
                        'port': 1,
                        'vlan': 1
                    },
                ],
            },
            'CLUSTERS': [
                {
                    'name': 'cluster1',
                    'adapter': 'CentOS_openstack',
                    'mutable': False,
                    'security': {
                        'server_credentials': {
                            'username': '******',
                            'password': '******'
                        },
                        'service_credentials': {
                            'username': '******',
                            'password': '******'
                        },
                        'console_credentials': {
                            'username': '******',
                            'password': '******'
                        }
                    },
                    'networking': {
                        'interfaces': {
                            'management': {
                                'nic': 'eth0',
                                'promisc': 0,
                                'netmask': '255.255.255.0',
                                'ip_end': '192.168.20.200',
                                'gateway': '',
                                'ip_start': '192.168.20.100'
                            },
                            'storage': {
                                'nic': 'eth0',
                                'promisc': 0,
                                'netmask': '255.255.254.0',
                                'ip_end': '10.145.88.200',
                                'gateway': '10.145.88.1',
                                'ip_start': '10.145.88.100'
                            },
                            'public': {
                                'nic': 'eth2',
                                'promisc': 1,
                                'netmask': '255.255.254.0',
                                'ip_end': '10.145.88.255',
                                'gateway': '10.145.88.1',
                                'ip_start': '10.145.88.100'
                            },
                            'tenant': {
                                'nic': 'eth0',
                                'promisc': 0,
                                'netmask': '255.255.254.0',
                                'ip_end': '10.145.88.120',
                                'gateway': '10.145.88.1',
                                'ip_start': '10.145.88.100'
                            }
                        },
                        'global': {
                            'nameservers': '192.168.20.254',
                            'proxy': 'http://192.168.20.254:3128',
                            'ntp_server': '192.168.20.254',
                            'search_path': 'ods.com',
                            'gateway': '10.145.88.1'
                        },
                    },
                    'partition': '/home 20%%;/tmp 10%%;/var 30%%;',
                },
            ],
            'HOSTS_BY_CLUSTER': {
                'cluster1': [
                    {
                        'hostname': 'server1',
                        'mac': '00:00:01:02:03:04',
                        'mutable': False,
                        'config': {
                            'networking': {
                                'interfaces': {
                                    'management': {
                                        'ip': '192.168.20.100',
                                    },
                                },
                            },
                            'roles': [
                                "os-single-controller",
                                "os-network",
                                "os-compute"
                            ],
                        },
                    },
                ],
            },
        }
        self._prepare_database(config)
        cluster_hosts = {}
        with database.session() as session:
            clusters = session.query(Cluster).all()
            for cluster in clusters:
                cluster_hosts[cluster.id] = [
                    host.id for host in cluster.hosts]

        test_update_progress = {
            'os_matcher': {
                'os_installer_name': 'cobbler',
                'os_pattern': 'CentOS.*',
                'item_matcher': self.os_item_matcher,
                'min_progress': 0.0,
                'max_progress': 0.6
            },
            'package_matcher': {
                'package_installer_name': 'chef',
                'target_system': 'openstack',
                'item_matcher': self.package_item_matcher,
                'min_progress': 0.6,
                'max_progress': 1.0
            }
        }
        os_matcher = adapter_matcher.OSMatcher(
            **test_update_progress['os_matcher'])
        package_matcher = adapter_matcher.PackageMatcher(
            **test_update_progress['package_matcher'])
        matcher = adapter_matcher.AdapterMatcher(
            os_matcher, package_matcher)
        for cluster_id in cluster_hosts.keys():
            matcher.update_progress(
                cluster_id,
                cluster_hosts[cluster_id])

        expected_cluster_state = {
            'state': 'INSTALLING',
            'progress': 0.0
        }
        cluster = {}
        host = {}
        with database.session():
            cluster_state = session.query(ClusterState).all()
            cluster['state'] = cluster_state[0].state
            cluster['progress'] = cluster_state[0].progress
            self.assertEqual(expected_cluster_state,
                             cluster)