weizhouapache commented on pull request #4399:
URL: https://github.com/apache/cloudstack/pull/4399#issuecomment-886462198
> > > > 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 ";
> > ```
> Hi @weizhouapache, You mean the same tag two times? Hmm .... sounds more
like a user input error. What do you think about a exception when user add the
same tag in host or service offerings or we add here a check for hosts and
service offering ?
@DK101010 yes, I agree it should not be allowed. but, since it is allowed in
4.15 and previous versions, it might already exists in some/few user
environments that a host have a same tag multiple times (who knows...).
IMHO options are
(1) check and throw an exception (as you said) or silently ignoring the
duplicated tags, and remove duplications in host_tags in next cloudstack
upgrade, or
(2) change your sql to take the scenario into consideration.
I would go for (1), but it looks (2) is much easier to you.
--
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]