weizhouapache commented on pull request #4399:
URL: https://github.com/apache/cloudstack/pull/4399#issuecomment-885599838


   > > found two bugs in testing
   > > (1) list hosts response lists only 1 host tag, although hosts have 
multiple host tags.
   > > for example
   > > ```
   > > (localcloud) SBCM5> > update host 
id=d9988a7b-7e02-4e90-9c4a-798c588b1cba hosttags=tag1,tag2
   > > {
   > >   "host": {
   > > ...
   > >     "hosttags": "tag2",
   > > ...
   > >   }
   > > }
   > > 
   > > (localcloud) SBCM5> > list hosts id=d9988a7b-7e02-4e90-9c4a-798c588b1cba 
filter=hosttags
   > > {
   > >   "count": 1,
   > >   "host": [
   > >     {
   > >       "hosttags": "tag2"
   > >     }
   > >   ]
   > > }
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > however in db, host has 2 tags.
   > > ```
   > > mysql> select * from host_tags;
   > > +----+---------+------+
   > > | id | host_id | tag  |
   > > +----+---------+------+
   > > | 29 |       4 | tag1 |
   > > | 30 |       4 | tag2 |
   > > +----+---------+------+
   > > 2 rows in set (0.00 sec)
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > (2) vm can be starteded on a host which does not have all tags.
   > > for example, service offering has host tags "tag1,tag2", and host has 
host tags "tag1,tag1".
   > > @DK101010 could you please fix the bugs above ?
   > 
   > Hi @weizhouapache, many thanks for testing. I'm a little bit confused, the 
logic doesn't use the list host method to find the right one. I wrote an sql to 
check this. Also we use this feature already for a long time without problems 
and I wrote test for this to get sure of this :/. Hmm ... how do you test this?
   
   @DK101010 
   ignore the first issue, I found the root cause: I upgraded the cloudstack 
packages but did not make the changes in #4796
   
   for 2nd issue, I use cmk for testing
   (1) update host to tag 'tag1,tag1'
   (2) create service offering, update host tag to 'tag1,tag2'
   (3) create vm with offering in (2)
   (4) start vm on the host in (1).
   
   expected result: vm is not started on host (1)
   actual result: vm is started on host (1) successfully.
   
   root cause: yo do not consider that host might have a tag multiple times. so 
you need to change the following sql
   ```
       private static final String LIST_HOST_IDS_BY_COMPUTETAGS = "SELECT 
host_id, COUNT(tag) AS tag_count "
                                                                + "FROM 
host_tags "
                                                                + "WHERE tag 
IN(%s) "
                                                                + "GROUP BY 
host_id "
                                                                + "HAVING 
tag_count = %s ";
   ```
   
https://github.com/apache/cloudstack/pull/4399/files#diff-ced268870eedefd01befd033d2544228bf010c0dccde9c76ac45f80652e503b8R84-R88
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to