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_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)