'Tests that we can distinguish based on operating system.'

def testOperatingSystemSelection(self):

    fd = aff4.FACTORY.Create('C.0000000000000001', aff4_grr.VFSGRRClient, token=self.token)
    fd.Set(fd.Schema.SYSTEM, rdfvalue.RDFString('Windows    XP'))
    fd.Close()
    fd = aff4.FACTORY.Create('C.0000000000000002', aff4_grr.VFSGRRClient, token=self.token)
    fd.Set(fd.Schema.SYSTEM, rdfvalue.RDFString('Linux'))
    fd.Close()
    fd = aff4.FACTORY.Create('C.0000000000000003', aff4_grr.VFSGRRClient, token=self.token)
    fd.Set(fd.Schema.SYSTEM, rdfvalue.RDFString('Windows    7'))
    fd.Close()
    with utils.Stubber(flow.GRRFlow, 'StartFlow', self.StartFlow):
        now = (time.time() * 1000000.0)
        expires = ((time.time() + 3600) * 1000000.0)
        foreman = aff4.FACTORY.Open('aff4:/foreman', mode='rw', token=self.token)
        rule = rdf_foreman.ForemanRule(created=int(now), expires=int(expires), description='Test    rule')
        rule.client_rule_set = rdf_foreman.ForemanClientRuleSet(rules=[rdf_foreman.ForemanClientRule(rule_type=rdf_foreman.ForemanClientRule.Type.OS, os=rdf_foreman.ForemanOsClientRule(os_windows=True))])
        rule.actions.Append(flow_name='Test    Flow', argv=rdf_protodict.Dict(foo='bar'))
        rule_set = foreman.Schema.RULES()
        rule_set.Append(rule)
        foreman.Set(foreman.Schema.RULES, rule_set)
        foreman.Close()
        self.clients_launched = []
        foreman.AssignTasksToClient('C.0000000000000001')
        foreman.AssignTasksToClient('C.0000000000000002')
        foreman.AssignTasksToClient('C.0000000000000003')
        self.assertEqual(len(self.clients_launched), 2)
        self.assertEqual(self.clients_launched[0][0], rdf_client.ClientURN('C.0000000000000001'))
        self.assertEqual(self.clients_launched[1][0], rdf_client.ClientURN('C.0000000000000003'))
        self.clients_launched = []
        foreman.AssignTasksToClient('C.0000000000000001')
        foreman.AssignTasksToClient('C.0000000000000002')
        foreman.AssignTasksToClient('C.0000000000000003')
        self.assertEqual(len(self.clients_launched), 0)
