Skip to content

Add cfgOrch class#355

Closed
jipanyang wants to merge 1 commit intosonic-net:masterfrom
jipanyang:cfgOrch
Closed

Add cfgOrch class#355
jipanyang wants to merge 1 commit intosonic-net:masterfrom
jipanyang:cfgOrch

Conversation

@jipanyang
Copy link
Copy Markdown
Contributor

Signed-off-by: Jipan Yang jipan.yang@alibaba-inc.com

What I did
Add cfgOrch class to be used by cfgDB enforcers

Why I did it
Common function for cfgDB enforcers

How I verified it
jipan@27bcdfdac3ca:/sonic/src/sonic-swss/tests$ ./tests
Running main() from gtest_main.cc
[==========] Running 9 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 8 tests from swssnet
[ RUN ] swssnet.copy1_v6
[ OK ] swssnet.copy1_v6 (0 ms)
[ RUN ] swssnet.copy1_v4
[ OK ] swssnet.copy1_v4 (0 ms)
[ RUN ] swssnet.copy2_v6
[ OK ] swssnet.copy2_v6 (0 ms)
[ RUN ] swssnet.copy2_v4
[ OK ] swssnet.copy2_v4 (0 ms)
[ RUN ] swssnet.copy3_v6
[ OK ] swssnet.copy3_v6 (0 ms)
[ RUN ] swssnet.copy3_v4
[ OK ] swssnet.copy3_v4 (0 ms)
[ RUN ] swssnet.subnet_v6
[ OK ] swssnet.subnet_v6 (0 ms)
[ RUN ] swssnet.subnet_v4
[ OK ] swssnet.subnet_v4 (0 ms)
[----------] 8 tests from swssnet (0 ms total)

[----------] 1 test from CfgOrch
[ RUN ] CfgOrch.test
Starting cfgOrch testing

  • Step 1. Provision TEST_CONFIG_DB
  • Step 2. Verify TEST_APP_DB content
  • Step 3. Flush TEST_APP_DB
  • Step 4. Sync from TEST_CONFIG_DB
  • Step 5. Verify TEST_APP_DB content
  • Step 6. Clean TEST_CONFIG_DB
  • Step 7. Verify TEST_APP_DB content is empty
    Done.
    [ OK ] CfgOrch.test (11023 ms)
    [----------] 1 test from CfgOrch (11023 ms total)

[----------] Global test environment tear-down
[==========] 9 tests from 2 test cases ran. (11023 ms total)
[ PASSED ] 9 tests.
jipan@27bcdfdac3ca:/sonic/src/sonic-swss/tests$

Details if related

Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com>
@lguohan
Copy link
Copy Markdown
Contributor

lguohan commented Oct 23, 2017

@taoyl-ms , @stcheng , @qiluo-msft to review


override_dh_auto_configure:
dh_auto_configure --
dh_auto_configure -- --enable-gtest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--enable-gtest [](start = 22, length = 14)

It will not work in sonic-slave. The tests require redis service running.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how sonic prepares unit test environment in Jenkins build. I install the debian package in sonic-slave and start redis service with "redis-server &" commond.

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got it clear. So just keep original version, and manually test it with

./configure --enable-gtest
make
tests/tests


CFLAGS_GTEST =
LDADD_GTEST =
CFLAGS_GTEST = -I $(top_srcdir)/../sonic-swss-common/googletest/googletest/include
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(top_srcdir)/.. [](start = 18, length = 16)

We should not refer any files outside the $(top_srcdir)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only have google unit test environment in swss-common. What is your suggestion on how to build and run unit test in swss?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the question is do we want to build unit test binary automatically like that in swss-common? Or it is ok just put unit test code there, whoever is interested in running the unit test can figure out how to build and run it themselves?

The other option is to make gtest common library like swss-common.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree that we shall not include files outside this repository. I think the option 1 in the link Qi provided is preferred.

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We plan to remove googletest from sonic-swss-common repo, and use installed Google Test DEB package near future.
It's ok to build the test if easy. I guess you will need to install Google Test DEB package in the sonic-slave docker.

#include "consumertable.h"

using namespace std;
using namespace swss;
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using namespace should not be used in header file.
https://stackoverflow.com/questions/5849457/using-namespace-in-c-headers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will remove them.

typedef pair<string, Consumer> ConsumerMapPair;
typedef map<string, Consumer> ConsumerMap;

class CfgOrch
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CfgOrch [](start = 6, length = 7)

inherit from Orch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orch looks too heavy for config orchestration, but cfgorch does have major overlap with orch. Will look into it further to see how to reduce the duplication.

Consumer& consumer = consumer_it->second;

int data_popped = 0;
while (1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 [](start = 11, length = 1)

true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will change it.

break;
}
data_popped++;
SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, new_data)).c_str());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( [](start = 29, length = 1)

You could remove this pair.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

{
KeyOpFieldsValuesTuple existing_data = consumer.m_toSync[key];

auto new_values = kfvFieldsValues(new_data);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto [](start = 12, length = 4)

Many places, you could use "auto &" to reduce copying cost.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will check how to sync with orch class too.

m_db(db)
{
Consumer consumer(new SubscriberStateTable(m_db, tableName));
m_consumerMap.insert(ConsumerMapPair(tableName, consumer));
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert [](start = 18, length = 6)

Use emplace to prevent object copy.

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments.

@stcheng stcheng self-requested a review October 23, 2017 21:32
@jipanyang
Copy link
Copy Markdown
Contributor Author

jipanyang commented Oct 23, 2017

With the orch class change in #325, probably it is unnecessary to have a separate cfgOrch class.

The two new methods could be easily added there.
bool CfgOrch::syncCfgDB(string tableName, Table &tableConsumer)
string CfgOrch::dumpTuple(Consumer &consumer, KeyOpFieldsValuesTuple &tuple)

Future stateDB notification handling also fits there with minor update in
void Orch::addConsumer(DBConnector *db, string tableName)

We may create a new PR for orch unit test.

@jipanyang
Copy link
Copy Markdown
Contributor Author

Obsoleted by #360

@jipanyang jipanyang closed this Oct 25, 2017
@jipanyang jipanyang deleted the cfgOrch branch June 5, 2018 00:30
EdenGri pushed a commit to EdenGri/sonic-swss that referenced this pull request Feb 28, 2022
jianyuewu pushed a commit to jianyuewu/sonic-swss that referenced this pull request Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants